@atmo-dev/kit 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +1 -1
  2. package/dist/articles/ArticleView.svelte +21 -7
  3. package/dist/articles/ArticleView.svelte.d.ts +8 -4
  4. package/dist/articles/styles.js +3 -2
  5. package/dist/articles-data.d.ts +1 -0
  6. package/dist/components/RichText.svelte +34 -17
  7. package/dist/components/RichText.svelte.d.ts +4 -1
  8. package/dist/components/RichTextEditor.svelte +67 -11
  9. package/dist/components/RichTextEditor.svelte.d.ts +0 -2
  10. package/dist/components/StreamplacePicker.svelte +2 -2
  11. package/dist/components/StreamplacePicker.svelte.d.ts +1 -1
  12. package/dist/components/composer/EmojiPanel.svelte +55 -0
  13. package/dist/components/composer/EmojiPanel.svelte.d.ts +6 -0
  14. package/dist/components/composer/EmojiPicker.svelte +2 -38
  15. package/dist/components/data/DataLabel.svelte +120 -0
  16. package/dist/components/data/DataLabel.svelte.d.ts +10 -0
  17. package/dist/components/data/issues.d.ts +5 -0
  18. package/dist/components/data/issues.js +52 -0
  19. package/dist/components/data/types.d.ts +28 -0
  20. package/dist/components/data/types.js +1 -0
  21. package/dist/components/data/visibility.d.ts +7 -0
  22. package/dist/components/data/visibility.js +15 -0
  23. package/dist/components/legal/links.js +1 -0
  24. package/dist/components/legal/types.d.ts +1 -1
  25. package/dist/components/notifications/NotificationList.svelte +137 -0
  26. package/dist/components/notifications/NotificationList.svelte.d.ts +19 -0
  27. package/dist/components/notifications/NotificationPushToggle.svelte +76 -0
  28. package/dist/components/notifications/NotificationPushToggle.svelte.d.ts +19 -0
  29. package/dist/components/notifications/NotificationSettings.svelte +125 -0
  30. package/dist/components/notifications/NotificationSettings.svelte.d.ts +16 -0
  31. package/dist/components/notifications/types.d.ts +37 -0
  32. package/dist/components/notifications/types.js +1 -0
  33. package/dist/editor/ImageDialog.svelte +87 -0
  34. package/dist/editor/ImageDialog.svelte.d.ts +16 -0
  35. package/dist/editor/image-node.d.ts +6 -2
  36. package/dist/editor/image-node.js +36 -37
  37. package/dist/events/EventCard.svelte +6 -1
  38. package/dist/events/VodPlayer.svelte +1 -1
  39. package/dist/events/atmo-rsvp.d.ts +6 -0
  40. package/dist/events/atmo-rsvp.js +34 -0
  41. package/dist/events/atproto-helpers.d.ts +1 -0
  42. package/dist/events/atproto-helpers.js +3 -0
  43. package/dist/events/event-link-embed.d.ts +7 -3
  44. package/dist/events/event-link-embed.js +11 -5
  45. package/dist/events/event-view/StreamPlacePlayer.svelte +14 -108
  46. package/dist/events/linked-records.d.ts +1 -1
  47. package/dist/events/linked-records.js +2 -2
  48. package/dist/events-card.d.ts +9 -0
  49. package/dist/events-card.js +7 -0
  50. package/dist/events-data.d.ts +1 -0
  51. package/dist/events-data.js +1 -0
  52. package/dist/grain/xrpc.js +11 -4
  53. package/dist/index.d.ts +14 -2
  54. package/dist/index.js +7 -1
  55. package/dist/legal.d.ts +3 -0
  56. package/dist/legal.js +2 -0
  57. package/dist/media.d.ts +33 -0
  58. package/dist/media.js +74 -1
  59. package/dist/richtext/serialize.js +13 -8
  60. package/dist/streamplace/StreamCard.svelte +184 -0
  61. package/dist/streamplace/StreamCard.svelte.d.ts +24 -0
  62. package/dist/streamplace/StreamLinkEmbed.svelte +59 -0
  63. package/dist/streamplace/StreamLinkEmbed.svelte.d.ts +5 -0
  64. package/dist/streamplace/StreamPlayer.svelte +539 -0
  65. package/dist/streamplace/StreamPlayer.svelte.d.ts +42 -0
  66. package/dist/streamplace/VideoCard.svelte +159 -0
  67. package/dist/streamplace/VideoCard.svelte.d.ts +17 -0
  68. package/dist/streamplace/api.d.ts +74 -0
  69. package/dist/streamplace/api.js +182 -0
  70. package/dist/streamplace/broadcast.d.ts +3 -0
  71. package/dist/streamplace/broadcast.js +110 -0
  72. package/dist/streamplace/channel.svelte.d.ts +74 -0
  73. package/dist/streamplace/channel.svelte.js +515 -0
  74. package/dist/streamplace/chat/Composer.svelte +232 -0
  75. package/dist/streamplace/chat/Composer.svelte.d.ts +15 -0
  76. package/dist/streamplace/chat/Embeds.svelte +135 -0
  77. package/dist/streamplace/chat/Embeds.svelte.d.ts +13 -0
  78. package/dist/streamplace/chat/Message.svelte +303 -0
  79. package/dist/streamplace/chat/Message.svelte.d.ts +25 -0
  80. package/dist/streamplace/chat/StreamChat.svelte +463 -0
  81. package/dist/streamplace/chat/StreamChat.svelte.d.ts +33 -0
  82. package/dist/streamplace/chat/StreamChatPopups.svelte +151 -0
  83. package/dist/streamplace/chat/StreamChatPopups.svelte.d.ts +15 -0
  84. package/dist/streamplace/chat/UserCard.svelte +76 -0
  85. package/dist/streamplace/chat/UserCard.svelte.d.ts +12 -0
  86. package/dist/streamplace/chat/color.d.ts +7 -0
  87. package/dist/streamplace/chat/color.js +33 -0
  88. package/dist/streamplace/chat/links.d.ts +10 -0
  89. package/dist/streamplace/chat/links.js +29 -0
  90. package/dist/streamplace/facets.d.ts +15 -0
  91. package/dist/streamplace/facets.js +112 -0
  92. package/dist/streamplace/link-embed.d.ts +13 -0
  93. package/dist/streamplace/link-embed.js +16 -0
  94. package/dist/streamplace/links.d.ts +6 -0
  95. package/dist/streamplace/links.js +1 -0
  96. package/dist/streamplace/reactions.d.ts +21 -0
  97. package/dist/streamplace/reactions.js +46 -0
  98. package/dist/streamplace/types.d.ts +200 -0
  99. package/dist/streamplace/types.js +1 -0
  100. package/dist/streamplace-data.d.ts +11 -0
  101. package/dist/streamplace-data.js +10 -0
  102. package/dist/streamplace.d.ts +14 -6
  103. package/dist/streamplace.js +11 -1
  104. package/dist/{events/event-view → video}/Player.svelte +69 -21
  105. package/dist/video/Player.svelte.d.ts +38 -0
  106. package/dist/video/engines.d.ts +59 -0
  107. package/dist/video/engines.js +647 -0
  108. package/package.json +11 -1
  109. package/dist/events/event-view/Player.svelte.d.ts +0 -24
@@ -0,0 +1,52 @@
1
+ import { safeLegalHref } from '../legal/links.js';
2
+ import { dataVisibilityLevels } from './visibility.js';
3
+ const nsid = /^[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+\.[a-zA-Z][a-zA-Z0-9]{0,62}$/;
4
+ const inAccount = new Set(['public', 'space']);
5
+ /** Same-page fragment anchors are allowed alongside paths, web URLs and mailto links. */
6
+ export function safeRemovalHref(value) {
7
+ if (value.startsWith('#') &&
8
+ value.length > 1 &&
9
+ !/\s/.test(value) &&
10
+ ![...value].some((c) => c === '\\' || c.charCodeAt(0) < 32 || c.charCodeAt(0) === 127))
11
+ return value;
12
+ return safeLegalHref(value, true);
13
+ }
14
+ /** Completeness checks only. They cannot tell whether the label matches what the app does. */
15
+ export function getDataLabelIssues(label) {
16
+ const issues = [];
17
+ if (!label.entries.length)
18
+ issues.push('List at least one thing the app saves.');
19
+ const seen = new Set();
20
+ for (const entry of label.entries) {
21
+ const action = entry.action.trim();
22
+ const name = action || '(unnamed)';
23
+ if (!action)
24
+ issues.push('An entry is missing its action.');
25
+ if (!entry.saves.trim())
26
+ issues.push(`"${name}" does not say what is saved.`);
27
+ if (!dataVisibilityLevels.some(({ id }) => id === entry.visibility))
28
+ issues.push(`"${name}" has an unknown visibility.`);
29
+ if (action) {
30
+ const key = `${entry.visibility}:${action.toLowerCase()}`;
31
+ if (seen.has(key))
32
+ issues.push(`"${name}" is listed twice.`);
33
+ seen.add(key);
34
+ }
35
+ if (entry.collection !== undefined) {
36
+ if (entry.collection.length > 317 || !nsid.test(entry.collection))
37
+ issues.push(`"${name}" has an invalid collection name.`);
38
+ if (!inAccount.has(entry.visibility))
39
+ issues.push(`"${name}" names a collection but is not saved to the account.`);
40
+ }
41
+ }
42
+ if (label.entries.some(({ visibility }) => inAccount.has(visibility)) && !label.removal)
43
+ issues.push('Add a link explaining how to delete account data.');
44
+ if (label.removal && (!label.removal.label.trim() || !safeRemovalHref(label.removal.href)))
45
+ issues.push('The delete link needs a label and a valid URL.');
46
+ if (label.updated !== undefined &&
47
+ (!/^\d{4}-\d{2}-\d{2}$/.test(label.updated) ||
48
+ !Number.isFinite(Date.parse(label.updated)) ||
49
+ new Date(label.updated).toISOString().slice(0, 10) !== label.updated))
50
+ issues.push('The updated date must be YYYY-MM-DD.');
51
+ return issues;
52
+ }
@@ -0,0 +1,28 @@
1
+ import type { IconNode } from '@sketchyicons/svelte';
2
+ import type { LegalLink } from '../legal/types.js';
3
+ /** Where a piece of data lives and who can read it, from most to least exposed. */
4
+ export type DataVisibility = 'public' | 'space' | 'app' | 'device';
5
+ export interface DataLabelEntry {
6
+ /** What the person does, e.g. "Like a station". */
7
+ action: string;
8
+ /** What is saved as a result, in plain words. */
9
+ saves: string;
10
+ visibility: DataVisibility;
11
+ icon?: IconNode;
12
+ /** Record collection NSID, shown small for people who want to look it up. */
13
+ collection?: string;
14
+ /** A caveat worth knowing, e.g. "Only the latest is kept." */
15
+ note?: string;
16
+ /** Only saved when the person opts in. */
17
+ optional?: boolean;
18
+ }
19
+ /** App-owned description of deployed behavior. Kit only owns the visibility wording. */
20
+ export interface DataLabelData {
21
+ entries: readonly DataLabelEntry[];
22
+ /** What works without signing in. */
23
+ withoutAccount?: string;
24
+ /** Where to learn how to delete saved data. */
25
+ removal?: LegalLink;
26
+ /** The app's reviewed revision date, not a Kit release date. */
27
+ updated?: string;
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { DataVisibility } from './types.js';
2
+ /** Fixed wording, so the same level reads the same in every app. */
3
+ export declare const dataVisibilityLevels: readonly {
4
+ id: DataVisibility;
5
+ label: string;
6
+ description: string;
7
+ }[];
@@ -0,0 +1,15 @@
1
+ /** Fixed wording, so the same level reads the same in every app. */
2
+ export const dataVisibilityLevels = [
3
+ { id: 'public', label: 'Public', description: 'Saved to your account. Anyone can see it.' },
4
+ {
5
+ id: 'space',
6
+ label: 'Shared privately',
7
+ description: 'Saved to your account. Only people you share it with can see it.'
8
+ },
9
+ {
10
+ id: 'app',
11
+ label: 'Stored by this app',
12
+ description: "Saved on this app's servers, not in your account."
13
+ },
14
+ { id: 'device', label: 'On this device', description: 'Saved only in your browser.' }
15
+ ];
@@ -15,6 +15,7 @@ export function safeLegalHref(value, allowMail = false) {
15
15
  const labels = {
16
16
  terms: 'Terms',
17
17
  privacy: 'Privacy',
18
+ data: 'Your data',
18
19
  imprint: 'Imprint',
19
20
  moderation: 'Moderation',
20
21
  report: 'Report',
@@ -21,7 +21,7 @@ export interface LegalDocumentData {
21
21
  }
22
22
  /** Omit a link, or set it to false, to hide it. */
23
23
  export type LegalFooterLink = string | false | LegalLink;
24
- export type LegalFooterLinks = Partial<Record<LegalDocumentKind | 'report' | 'source', LegalFooterLink>>;
24
+ export type LegalFooterLinks = Partial<Record<LegalDocumentKind | 'data' | 'report' | 'source', LegalFooterLink>>;
25
25
  export interface LegalDraftConfig {
26
26
  app: {
27
27
  name: string;
@@ -0,0 +1,137 @@
1
+ <script lang="ts" module>
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import type { NotificationItem } from './types.js';
4
+ export type NotificationListProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
5
+ items: readonly NotificationItem[];
6
+ /** Called when an item is activated, before navigation. Items without a link become buttons. */
7
+ onopen?: (item: NotificationItem) => void;
8
+ /** Shown when there are no items. */
9
+ empty?: string;
10
+ /** Text for the unread marker, for assistive technology. */
11
+ unreadLabel?: string;
12
+ locale?: string;
13
+ /** Time zone for calendar dates; defaults to the runtime's. */
14
+ timeZone?: string;
15
+ /** Reference time for relative dates; defaults to the current time. */
16
+ now?: number;
17
+ };
18
+
19
+ const steps: Array<[Intl.RelativeTimeFormatUnit, number]> = [
20
+ ['minute', 60_000],
21
+ ['hour', 3_600_000],
22
+ ['day', 86_400_000]
23
+ ];
24
+ </script>
25
+
26
+ <script lang="ts">
27
+ import { cn } from '../../utils.js';
28
+ import { focus, hoverRecess } from '../../styles.js';
29
+ import { safeLinkHref, safeHttpUrl } from '../../urls.js';
30
+ import Avatar from '../Avatar.svelte';
31
+
32
+ let {
33
+ items,
34
+ onopen,
35
+ empty = 'No notifications yet.',
36
+ unreadLabel = 'Unread',
37
+ locale,
38
+ timeZone,
39
+ now = Date.now(),
40
+ class: className,
41
+ ...rest
42
+ }: NotificationListProps = $props();
43
+
44
+ const relative = $derived(new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }));
45
+ const absolute = $derived(new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeZone }));
46
+ const row = 'flex items-start gap-3 px-2 py-3';
47
+ const interactive = cn(
48
+ 'rounded-ui no-underline transition-colors duration-(--atmo-duration) motion-reduce:transition-none',
49
+ hoverRecess,
50
+ focus
51
+ );
52
+
53
+ function link(item: NotificationItem) {
54
+ const href = safeLinkHref(item.uri);
55
+ return href && (href.startsWith('/') || href.startsWith('#') || safeHttpUrl(href))
56
+ ? href
57
+ : undefined;
58
+ }
59
+
60
+ function iso(time: number) {
61
+ const date = new Date(time);
62
+ return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
63
+ }
64
+
65
+ function when(time: number) {
66
+ if (!Number.isFinite(time)) return '';
67
+ const elapsed = Math.max(0, (Number.isFinite(now) ? now : Date.now()) - time);
68
+ if (elapsed < 60_000) return relative.format(0, 'second');
69
+ if (elapsed >= 7 * 86_400_000) return absolute.format(time);
70
+ const [unit, size] = steps.findLast(([, size]) => elapsed >= size)!;
71
+ return relative.format(-Math.floor(elapsed / size), unit);
72
+ }
73
+ </script>
74
+
75
+ {#snippet content(item: NotificationItem)}
76
+ {@const actor = item.actors?.[0]}
77
+ {@const unread = item.readAt == null}
78
+ {@const datetime = iso(item.sendAt)}
79
+ {#if actor}
80
+ <Avatar
81
+ name={actor.displayName || actor.handle || actor.did}
82
+ src={actor.avatar}
83
+ size={36}
84
+ aria-hidden="true"
85
+ />
86
+ {/if}
87
+ <span class="flex min-w-0 flex-1 flex-col gap-0.5 wrap-anywhere">
88
+ <span class={cn('text-sm text-base-950 dark:text-base-50', unread && 'font-semibold')}>
89
+ {item.title}
90
+ </span>
91
+ {#if item.body}
92
+ <span class="text-sm text-base-600 dark:text-base-400">{item.body}</span>
93
+ {/if}
94
+ {#if datetime}
95
+ <time class="text-xs text-base-600 dark:text-base-400" {datetime}>
96
+ {when(item.sendAt)}
97
+ </time>
98
+ {/if}
99
+ </span>
100
+ {#if unread}
101
+ <span
102
+ class="mt-1.5 size-2 shrink-0 rounded-full bg-accent-700 dark:bg-accent-300"
103
+ aria-hidden="true"
104
+ ></span>
105
+ <span class="sr-only">{unreadLabel}</span>
106
+ {/if}
107
+ {/snippet}
108
+
109
+ {#if items.length === 0}
110
+ <p {...rest} class={cn('text-sm text-base-600 dark:text-base-400', className)}>{empty}</p>
111
+ {:else}
112
+ <ul
113
+ {...rest}
114
+ class={cn('m-0 list-none divide-y divide-base-200 p-0 dark:divide-base-800', className)}
115
+ >
116
+ {#each items as item (item.id)}
117
+ {@const href = link(item)}
118
+ <li>
119
+ {#if href}
120
+ <a {href} onclick={() => onopen?.(item)} class={cn(row, interactive)}>
121
+ {@render content(item)}
122
+ </a>
123
+ {:else if onopen}
124
+ <button
125
+ type="button"
126
+ onclick={() => onopen(item)}
127
+ class={cn(row, interactive, 'w-full cursor-pointer text-left')}
128
+ >
129
+ {@render content(item)}
130
+ </button>
131
+ {:else}
132
+ <div class={row}>{@render content(item)}</div>
133
+ {/if}
134
+ </li>
135
+ {/each}
136
+ </ul>
137
+ {/if}
@@ -0,0 +1,19 @@
1
+ import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { NotificationItem } from './types.js';
3
+ export type NotificationListProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
4
+ items: readonly NotificationItem[];
5
+ /** Called when an item is activated, before navigation. Items without a link become buttons. */
6
+ onopen?: (item: NotificationItem) => void;
7
+ /** Shown when there are no items. */
8
+ empty?: string;
9
+ /** Text for the unread marker, for assistive technology. */
10
+ unreadLabel?: string;
11
+ locale?: string;
12
+ /** Time zone for calendar dates; defaults to the runtime's. */
13
+ timeZone?: string;
14
+ /** Reference time for relative dates; defaults to the current time. */
15
+ now?: number;
16
+ };
17
+ declare const NotificationList: import("svelte").Component<NotificationListProps, {}, "">;
18
+ type NotificationList = ReturnType<typeof NotificationList>;
19
+ export default NotificationList;
@@ -0,0 +1,76 @@
1
+ <script lang="ts" module>
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import type { NotificationPushState } from './types.js';
4
+ export type NotificationPushToggleProps = Omit<
5
+ HTMLAttributes<HTMLElement>,
6
+ 'children' | 'onclick'
7
+ > & {
8
+ state: NotificationPushState;
9
+ /** True while a change is in progress. */
10
+ loading?: boolean;
11
+ disabled?: boolean;
12
+ onenable: () => void;
13
+ ondisable: () => void;
14
+ labels?: Partial<{ enable: string; disable: string; unsupported: string; denied: string }>;
15
+ };
16
+ </script>
17
+
18
+ <script lang="ts">
19
+ import { tick, untrack } from 'svelte';
20
+ import { cn } from '../../utils.js';
21
+ import { focus } from '../../styles.js';
22
+ import Button from '../Button.svelte';
23
+
24
+ let {
25
+ state: push,
26
+ loading = false,
27
+ disabled = false,
28
+ onenable,
29
+ ondisable,
30
+ labels,
31
+ class: className,
32
+ ...rest
33
+ }: NotificationPushToggleProps = $props();
34
+
35
+ let button = $state<HTMLButtonElement | HTMLAnchorElement | null>(null);
36
+ let blocked = $state<HTMLParagraphElement | null>(null);
37
+ // When the browser blocks the request, the button is replaced by the explanation.
38
+ // Move focus there so it is neither lost nor left unannounced.
39
+ $effect.pre(() => {
40
+ if (push !== 'denied') return;
41
+ const current = untrack(() => button);
42
+ if (current && document.activeElement === current) void tick().then(() => blocked?.focus());
43
+ });
44
+ </script>
45
+
46
+ {#if push === 'unsupported'}
47
+ <p {...rest} class={cn('text-sm text-base-600 dark:text-base-400', className)}>
48
+ {labels?.unsupported ??
49
+ 'This browser does not support push notifications. On iPhone and iPad, add this site to your Home Screen first.'}
50
+ </p>
51
+ {:else if push === 'denied'}
52
+ <p
53
+ role="status"
54
+ tabindex="-1"
55
+ {...rest}
56
+ bind:this={blocked}
57
+ class={cn('rounded text-sm text-base-600 dark:text-base-400', focus, className)}
58
+ >
59
+ {labels?.denied ??
60
+ 'Notifications are blocked for this site. Allow them in your browser settings to turn on push.'}
61
+ </p>
62
+ {:else}
63
+ <Button
64
+ {...rest}
65
+ bind:ref={button}
66
+ variant={push === 'on' ? 'secondary' : 'primary'}
67
+ {loading}
68
+ disabled={disabled || loading}
69
+ onclick={push === 'on' ? ondisable : onenable}
70
+ class={className}
71
+ >
72
+ {push === 'on'
73
+ ? (labels?.disable ?? 'Turn off push on this device')
74
+ : (labels?.enable ?? 'Turn on push on this device')}
75
+ </Button>
76
+ {/if}
@@ -0,0 +1,19 @@
1
+ import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { NotificationPushState } from './types.js';
3
+ export type NotificationPushToggleProps = Omit<HTMLAttributes<HTMLElement>, 'children' | 'onclick'> & {
4
+ state: NotificationPushState;
5
+ /** True while a change is in progress. */
6
+ loading?: boolean;
7
+ disabled?: boolean;
8
+ onenable: () => void;
9
+ ondisable: () => void;
10
+ labels?: Partial<{
11
+ enable: string;
12
+ disable: string;
13
+ unsupported: string;
14
+ denied: string;
15
+ }>;
16
+ };
17
+ declare const NotificationPushToggle: import("svelte").Component<NotificationPushToggleProps, {}, "">;
18
+ type NotificationPushToggle = ReturnType<typeof NotificationPushToggle>;
19
+ export default NotificationPushToggle;
@@ -0,0 +1,125 @@
1
+ <script lang="ts" module>
2
+ import type { HTMLTableAttributes } from 'svelte/elements';
3
+ import type {
4
+ NotificationChannel,
5
+ NotificationPreference,
6
+ NotificationPreferenceValue
7
+ } from './types.js';
8
+ export type NotificationSettingsProps = Omit<HTMLTableAttributes, 'children' | 'onchange'> & {
9
+ preferences: readonly NotificationPreference[];
10
+ /** Extra delivery channels to offer, e.g. `{ id: 'push', label: 'Push' }`. */
11
+ channels?: readonly NotificationChannel[];
12
+ /** Column heading for the in-app list. */
13
+ inAppLabel?: string;
14
+ /** Action for a category with custom settings. */
15
+ resetLabel?: string;
16
+ disabled?: boolean;
17
+ onchange: (category: string, value: NotificationPreferenceValue) => void;
18
+ };
19
+ </script>
20
+
21
+ <script lang="ts">
22
+ import { cn } from '../../utils.js';
23
+ import Checkbox from '../Checkbox.svelte';
24
+ import Button from '../Button.svelte';
25
+
26
+ let {
27
+ preferences,
28
+ channels = [],
29
+ inAppLabel = 'In app',
30
+ resetLabel = 'Use default',
31
+ disabled = false,
32
+ onchange,
33
+ class: className,
34
+ ...rest
35
+ }: NotificationSettingsProps = $props();
36
+
37
+ function toggleChannel(preference: NotificationPreference, channel: string, on: boolean) {
38
+ const rest = preference.channels.filter((id) => id !== channel);
39
+ onchange(preference.category, on ? [...rest, channel] : rest);
40
+ }
41
+ </script>
42
+
43
+ {#snippet choice(
44
+ label: string,
45
+ checked: boolean,
46
+ unavailable: boolean,
47
+ change: (next: boolean) => void
48
+ )}
49
+ <label
50
+ class={cn(
51
+ 'inline-flex size-10 items-center justify-center',
52
+ unavailable ? 'cursor-not-allowed' : 'cursor-pointer'
53
+ )}
54
+ >
55
+ <Checkbox
56
+ aria-label={label}
57
+ bind:checked={() => checked, () => {}}
58
+ disabled={unavailable}
59
+ onchange={(event) => {
60
+ // A click changes the native input before dispatching change. Restore the
61
+ // committed value now; only a new preference should update the display.
62
+ const next = event.currentTarget.checked;
63
+ event.currentTarget.checked = checked;
64
+ change(next);
65
+ }}
66
+ />
67
+ </label>
68
+ {/snippet}
69
+
70
+ {#if preferences.length > 0}
71
+ <table {...rest} class={cn('w-full border-collapse text-sm', className)}>
72
+ <thead>
73
+ <tr class="text-xs text-base-600 dark:text-base-400">
74
+ <td></td>
75
+ <th scope="col" class="min-w-16 px-2 pb-2 text-center font-normal">{inAppLabel}</th>
76
+ {#each channels as channel (channel.id)}
77
+ <th scope="col" class="min-w-16 px-2 pb-2 text-center font-normal">{channel.label}</th>
78
+ {/each}
79
+ </tr>
80
+ </thead>
81
+ <tbody>
82
+ {#each preferences as preference (preference.category)}
83
+ <tr>
84
+ <th scope="row" class="py-2 pr-3 text-left font-normal text-base-950 dark:text-base-50">
85
+ {preference.title}
86
+ {#if preference.description}
87
+ <span class="block text-xs text-base-600 dark:text-base-400">
88
+ {preference.description}
89
+ </span>
90
+ {/if}
91
+ {#if preference.isDefault === false}
92
+ <div class="mt-0.5">
93
+ <Button
94
+ variant="link"
95
+ class="text-xs"
96
+ {disabled}
97
+ aria-label={`${preference.title}: ${resetLabel}`}
98
+ onclick={() => onchange(preference.category, null)}>{resetLabel}</Button
99
+ >
100
+ </div>
101
+ {/if}
102
+ </th>
103
+ <td class="px-1 text-center">
104
+ {@render choice(
105
+ `${preference.title}: ${inAppLabel}`,
106
+ preference.enabled,
107
+ disabled,
108
+ (next) => onchange(preference.category, next ? null : 'off')
109
+ )}
110
+ </td>
111
+ {#each channels as channel (channel.id)}
112
+ <td class="px-1 text-center">
113
+ {@render choice(
114
+ `${preference.title}: ${channel.label}`,
115
+ preference.enabled && preference.channels.includes(channel.id),
116
+ disabled || !preference.enabled,
117
+ (next) => toggleChannel(preference, channel.id, next)
118
+ )}
119
+ </td>
120
+ {/each}
121
+ </tr>
122
+ {/each}
123
+ </tbody>
124
+ </table>
125
+ {/if}
@@ -0,0 +1,16 @@
1
+ import type { HTMLTableAttributes } from 'svelte/elements';
2
+ import type { NotificationChannel, NotificationPreference, NotificationPreferenceValue } from './types.js';
3
+ export type NotificationSettingsProps = Omit<HTMLTableAttributes, 'children' | 'onchange'> & {
4
+ preferences: readonly NotificationPreference[];
5
+ /** Extra delivery channels to offer, e.g. `{ id: 'push', label: 'Push' }`. */
6
+ channels?: readonly NotificationChannel[];
7
+ /** Column heading for the in-app list. */
8
+ inAppLabel?: string;
9
+ /** Action for a category with custom settings. */
10
+ resetLabel?: string;
11
+ disabled?: boolean;
12
+ onchange: (category: string, value: NotificationPreferenceValue) => void;
13
+ };
14
+ declare const NotificationSettings: import("svelte").Component<NotificationSettingsProps, {}, "">;
15
+ type NotificationSettings = ReturnType<typeof NotificationSettings>;
16
+ export default NotificationSettings;
@@ -0,0 +1,37 @@
1
+ /** Someone a notification is about, e.g. the person who replied. */
2
+ export type NotificationActor = {
3
+ did: string;
4
+ handle?: string;
5
+ displayName?: string;
6
+ avatar?: string;
7
+ };
8
+ export type NotificationItem = {
9
+ id: string;
10
+ title: string;
11
+ body?: string | null;
12
+ /** Where the notification leads. Items without one are not links. */
13
+ uri?: string | null;
14
+ actors?: NotificationActor[];
15
+ /** When it was sent, in milliseconds since the epoch. */
16
+ sendAt: number;
17
+ /** When it was read; empty while unread. */
18
+ readAt?: number | null;
19
+ };
20
+ export type NotificationPreference = {
21
+ category: string;
22
+ title: string;
23
+ description?: string | null;
24
+ /** False when the person turned the category off entirely. */
25
+ enabled: boolean;
26
+ /** Channels, such as `push`, used in addition to the in-app list. */
27
+ channels: string[];
28
+ /** Whether this category uses app defaults. Omit to hide the reset action. */
29
+ isDefault?: boolean;
30
+ };
31
+ export type NotificationChannel = {
32
+ id: string;
33
+ label: string;
34
+ };
35
+ /** Channels to use (empty for in-app only), `'off'` for nothing, or `null` for defaults. */
36
+ export type NotificationPreferenceValue = string[] | 'off' | null;
37
+ export type NotificationPushState = 'unsupported' | 'denied' | 'off' | 'on';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,87 @@
1
+ <script lang="ts">
2
+ import Button from '../components/Button.svelte';
3
+ import Input from '../components/Input.svelte';
4
+ import Label from '../components/Label.svelte';
5
+ import Modal from '../components/Modal.svelte';
6
+ import Textarea from '../components/Textarea.svelte';
7
+ import { recess } from '../styles.js';
8
+
9
+ // The description and caption of an image in an article being written.
10
+ let {
11
+ open = $bindable(false),
12
+ src,
13
+ alt,
14
+ caption,
15
+ onsave,
16
+ onremove,
17
+ onCloseAutoFocus
18
+ }: {
19
+ open?: boolean;
20
+ /** The image, shown so that it can be described while looking at it. */
21
+ src?: string;
22
+ alt: string;
23
+ caption: string;
24
+ onsave: (values: { alt: string; caption: string }) => void;
25
+ onremove: () => void;
26
+ onCloseAutoFocus?: (event: Event) => void;
27
+ } = $props();
28
+
29
+ const id = $props.id();
30
+ const clean = (value: string) => value.replace(/\s*[\r\n]+\s*/g, ' ').trim();
31
+ let altText = $state('');
32
+ let captionText = $state('');
33
+ let wasOpen = false;
34
+ $effect(() => {
35
+ if (open && !wasOpen) {
36
+ altText = alt;
37
+ captionText = caption;
38
+ }
39
+ wasOpen = open;
40
+ });
41
+ </script>
42
+
43
+ <Modal bind:open title="Image" class="max-w-md" {onCloseAutoFocus}>
44
+ <form
45
+ class="grid gap-4"
46
+ onsubmit={(event) => {
47
+ event.preventDefault();
48
+ onsave({ alt: clean(altText), caption: clean(captionText) });
49
+ open = false;
50
+ }}
51
+ >
52
+ {#if src}
53
+ <img
54
+ {src}
55
+ alt=""
56
+ referrerpolicy="no-referrer"
57
+ class="max-h-56 w-full rounded-ui object-contain {recess}"
58
+ />
59
+ {/if}
60
+ <div class="grid gap-1.5">
61
+ <Label for="{id}-alt">Alt text</Label>
62
+ <Textarea
63
+ id="{id}-alt"
64
+ bind:value={altText}
65
+ rows={3}
66
+ class="min-h-20"
67
+ placeholder="Describe this for people who can't see it"
68
+ data-autofocus
69
+ />
70
+ </div>
71
+ <div class="grid gap-1.5">
72
+ <Label for="{id}-caption">Caption</Label>
73
+ <Input id="{id}-caption" bind:value={captionText} placeholder="Shown under the image" />
74
+ </div>
75
+ <div class="flex items-center justify-between gap-3">
76
+ <Button
77
+ variant="ghost"
78
+ class="-ml-3"
79
+ onclick={() => {
80
+ onremove();
81
+ open = false;
82
+ }}>Remove</Button
83
+ >
84
+ <Button type="submit">Save</Button>
85
+ </div>
86
+ </form>
87
+ </Modal>
@@ -0,0 +1,16 @@
1
+ type $$ComponentProps = {
2
+ open?: boolean;
3
+ /** The image, shown so that it can be described while looking at it. */
4
+ src?: string;
5
+ alt: string;
6
+ caption: string;
7
+ onsave: (values: {
8
+ alt: string;
9
+ caption: string;
10
+ }) => void;
11
+ onremove: () => void;
12
+ onCloseAutoFocus?: (event: Event) => void;
13
+ };
14
+ declare const ImageDialog: import("svelte").Component<$$ComponentProps, {}, "open">;
15
+ type ImageDialog = ReturnType<typeof ImageDialog>;
16
+ export default ImageDialog;