@atmo-dev/kit 0.15.0 → 0.16.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.
@@ -150,8 +150,9 @@
150
150
  const editorClass =
151
151
  'min-h-[1.5em] outline-none break-words [&_p.is-editor-empty:first-child]:before:content-[attr(data-placeholder)] [&_p.is-editor-empty:first-child]:before:text-base-600 dark:[&_p.is-editor-empty:first-child]:before:text-base-400 [&_p.is-editor-empty:first-child]:before:float-left [&_p.is-editor-empty:first-child]:before:pointer-events-none [&_p.is-editor-empty:first-child]:before:h-0 [&_[data-link-embed]]:whitespace-normal [&_.ProseMirror-selectednode]:rounded-ui [&_.ProseMirror-selectednode]:outline-2 [&_.ProseMirror-selectednode]:outline-offset-2 [&_.ProseMirror-selectednode]:outline-accent-700 dark:[&_.ProseMirror-selectednode]:outline-accent-300';
152
152
  // The same look as `RichText`, so that what is typed is what will be shown.
153
+ // Nothing here reaches into an embed, which brings its own lists, links and code.
153
154
  const markdownClass =
154
- 'space-y-3 leading-relaxed whitespace-pre-wrap [&_strong]:font-semibold [&_h1]:text-xl [&_h2]:text-lg [&_:is(h1,h2,h3,h4,h5,h6)]:leading-snug [&_:is(h1,h2,h3,h4,h5,h6)]:font-semibold [&_blockquote]:space-y-3 [&_blockquote]:border-l-2 [&_blockquote]:border-base-300 [&_blockquote]:pl-4 dark:[&_blockquote]:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] [&_:is(ul,ol)]:space-y-1 [&_:is(ul,ol)]:pl-6 [&_ul]:list-disc [&_ol]:list-decimal [&_li]:space-y-3 [&_:not(pre)>code]:rounded [&_:not(pre)>code]:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] [&_:not(pre)>code]:px-1 [&_:not(pre)>code]:py-0.5 [&_:not(pre)>code]:font-mono [&_:not(pre)>code]:text-[0.875em] dark:[&_:not(pre)>code]:bg-base-950 [&_pre]:overflow-x-auto [&_pre]:rounded-md [&_pre]:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] [&_pre]:p-3 [&_pre]:font-mono [&_pre]:text-[0.875em] dark:[&_pre]:bg-base-950 [&_hr]:border-base-300 dark:[&_hr]:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] [&_a]:text-accent-700 [&_a]:underline [&_a]:decoration-accent-700/40 [&_a]:underline-offset-2 dark:[&_a]:text-accent-300 dark:[&_a]:decoration-accent-300/40';
155
+ 'space-y-3 leading-relaxed whitespace-pre-wrap [&_strong:not([data-link-embed]_*)]:font-semibold [&_h1:not([data-link-embed]_*)]:text-xl [&_h2:not([data-link-embed]_*)]:text-lg [&_:is(h1,h2,h3,h4,h5,h6):not([data-link-embed]_*)]:leading-snug [&_:is(h1,h2,h3,h4,h5,h6):not([data-link-embed]_*)]:font-semibold [&_blockquote:not([data-link-embed]_*)]:space-y-3 [&_blockquote:not([data-link-embed]_*)]:border-l-2 [&_blockquote:not([data-link-embed]_*)]:border-base-300 [&_blockquote:not([data-link-embed]_*)]:pl-4 dark:[&_blockquote:not([data-link-embed]_*)]:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] [&_:is(ul,ol):not([data-link-embed]_*)]:space-y-1 [&_:is(ul,ol):not([data-link-embed]_*)]:pl-6 [&_ul:not([data-link-embed]_*)]:list-disc [&_ol:not([data-link-embed]_*)]:list-decimal [&_li:not([data-link-embed]_*)]:space-y-3 [&_:not(pre)>code:not([data-link-embed]_*)]:rounded [&_:not(pre)>code:not([data-link-embed]_*)]:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] [&_:not(pre)>code:not([data-link-embed]_*)]:px-1 [&_:not(pre)>code:not([data-link-embed]_*)]:py-0.5 [&_:not(pre)>code:not([data-link-embed]_*)]:font-mono [&_:not(pre)>code:not([data-link-embed]_*)]:text-[0.875em] dark:[&_:not(pre)>code:not([data-link-embed]_*)]:bg-base-950 [&_pre:not([data-link-embed]_*)]:overflow-x-auto [&_pre:not([data-link-embed]_*)]:rounded-md [&_pre:not([data-link-embed]_*)]:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] [&_pre:not([data-link-embed]_*)]:p-3 [&_pre:not([data-link-embed]_*)]:font-mono [&_pre:not([data-link-embed]_*)]:text-[0.875em] dark:[&_pre:not([data-link-embed]_*)]:bg-base-950 [&_hr:not([data-link-embed]_*)]:border-base-300 dark:[&_hr:not([data-link-embed]_*)]:border-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))] [&_a:not([data-link-embed]_*)]:text-accent-700 [&_a:not([data-link-embed]_*)]:underline [&_a:not([data-link-embed]_*)]:decoration-accent-700/40 [&_a:not([data-link-embed]_*)]:underline-offset-2 dark:[&_a:not([data-link-embed]_*)]:text-accent-300 dark:[&_a:not([data-link-embed]_*)]:decoration-accent-300/40';
155
156
 
156
157
  onMount(() => {
157
158
  let instance: Editor | undefined;
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { getCDNImageBlobUrl } from './atproto-helpers.js';
3
- import { getEventThumbnail, getEventExternalImage } from './event-media.js';
3
+ import { getEventThumbnail, getEventExternalImage, type EventMediaUrl } from './event-media.js';
4
4
  import { eventUrl, isEventOngoing, type FlatEventRecord } from './contrail.js';
5
5
  import Avatar from 'svelte-boring-avatars';
6
6
  import { Badge, Icon } from '../index.js';
@@ -10,12 +10,15 @@
10
10
  let {
11
11
  event,
12
12
  actor,
13
- href
13
+ href,
14
+ mediaUrl = getCDNImageBlobUrl
14
15
  }: {
15
16
  event: FlatEventRecord;
16
17
  actor?: string;
17
18
  /** Where the card links, for an event whose page is not its creator's. */
18
19
  href?: string;
20
+ /** Where the card loads the event's own images from; the public CDN by default. */
21
+ mediaUrl?: EventMediaUrl;
19
22
  } = $props();
20
23
 
21
24
  function formatDateTime(dateStr: string): string {
@@ -68,13 +71,13 @@
68
71
  function getThumbnail(event: FlatEventRecord): { url: string; alt: string } | null {
69
72
  const media = getEventThumbnail(event.media);
70
73
  if (media?.content) {
71
- const url = getCDNImageBlobUrl({ did: event.did, blob: media.content });
74
+ const url = mediaUrl({ did: event.did, blob: media.content });
72
75
  if (url) return { url, alt: media.alt || event.name };
73
76
  }
74
77
 
75
78
  const banner = event.media?.find((m) => m.role === 'header');
76
79
  if (banner?.content) {
77
- const url = getCDNImageBlobUrl({ did: event.did, blob: banner.content });
80
+ const url = mediaUrl({ did: event.did, blob: banner.content });
78
81
  if (url) return { url, alt: banner.alt || event.name };
79
82
  }
80
83
 
@@ -1,9 +1,12 @@
1
+ import { type EventMediaUrl } from './event-media.js';
1
2
  import { type FlatEventRecord } from './contrail.js';
2
3
  type $$ComponentProps = {
3
4
  event: FlatEventRecord;
4
5
  actor?: string;
5
6
  /** Where the card links, for an event whose page is not its creator's. */
6
7
  href?: string;
8
+ /** Where the card loads the event's own images from; the public CDN by default. */
9
+ mediaUrl?: EventMediaUrl;
7
10
  };
8
11
  declare const EventCard: import("svelte").Component<$$ComponentProps, {}, "">;
9
12
  type EventCard = ReturnType<typeof EventCard>;
@@ -1,9 +1,11 @@
1
1
  <script lang="ts">
2
2
  import { getCDNImageBlobUrl } from './atproto-helpers.js';
3
- import { getEventThumbnail } from './event-media.js';
3
+ import { getEventThumbnail, type EventMediaUrl } from './event-media.js';
4
4
  import { Avatar, Button, ToggleGroup, ToggleGroupItem } from '../index.js';
5
5
  import { onMount, untrack } from 'svelte';
6
6
  import { InlineEditor, RichTextEditor, type Editor } from '../index.js';
7
+ import { linkEmbedOptions, selectLinkEmbeds } from '../embeds/context.js';
8
+ import { eventLinkEmbed } from './event-link-embed.js';
7
9
  import DateTimePicker from '../components/DateTimePicker.svelte';
8
10
  import TimezonePicker from '../components/TimezonePicker.svelte';
9
11
  import { parseDateTime } from '@internationalized/date';
@@ -37,7 +39,8 @@
37
39
  adapter,
38
40
  viewer,
39
41
  initialTheme,
40
- prefill = null
42
+ prefill = null,
43
+ mediaUrl = getCDNImageBlobUrl
41
44
  }: {
42
45
  eventData: FlatEventRecord | null;
43
46
  actorDid: string;
@@ -48,6 +51,8 @@
48
51
  initialTheme?: Partial<EventTheme>;
49
52
  /** Autofill payload for new events (e.g. imported from Luma/Meetup). */
50
53
  prefill?: EventEditorPrefill | null;
54
+ /** Where the editor loads the event's current image from; the public CDN by default. */
55
+ mediaUrl?: EventMediaUrl;
51
56
  } = $props();
52
57
 
53
58
  let isNew = $derived(eventData === null);
@@ -94,7 +99,30 @@
94
99
  let selectedPreset: string | null = $state(
95
100
  initialThumbnailFile ? null : eventData === null ? DEFAULT_PRESET : null
96
101
  );
102
+ /** The cover drawn from the selected preset, once it is drawn for a save. */
103
+ let generatedThumbnail: File | null = null;
104
+ /** The host chose a cover, or took it away, rather than leaving a new event's default. */
105
+ let coverChosen = false;
97
106
  let images = $derived(adapter.features.images !== false);
107
+ const embedOptions = linkEmbedOptions();
108
+ /** As on the event page: the app's embeds, plus cards for links to other events. */
109
+ let descriptionEmbeds = $derived.by(() => {
110
+ const loadEvent = adapter.linkedRecords?.getEvent;
111
+ const origin = globalThis.location?.origin;
112
+ return [
113
+ ...(loadEvent
114
+ ? [
115
+ eventLinkEmbed({
116
+ loadEvent,
117
+ origins: [...new Set(['https://atmo.rsvp', ...(origin ? [origin] : [])])],
118
+ skip: (link) =>
119
+ link.rkey === rkey && (link.actor === actorDid || link.actor === viewer.handle)
120
+ })
121
+ ]
122
+ : []),
123
+ ...selectLinkEmbeds(true, embedOptions())
124
+ ];
125
+ });
98
126
  let showVisibility = $derived(adapter.features.visibility !== false);
99
127
  let submitting = $state(false);
100
128
  let error: string | null = $state(null);
@@ -138,7 +166,7 @@
138
166
  if (eventData.media && eventData.media.length > 0) {
139
167
  const media = getEventThumbnail(eventData.media);
140
168
  if (media?.content) {
141
- const url = getCDNImageBlobUrl({ did: actorDid, blob: media.content });
169
+ const url = mediaUrl({ did: actorDid, blob: media.content });
142
170
  if (url) {
143
171
  thumbnailPreview = url;
144
172
  thumbnailChanged = false;
@@ -224,9 +252,19 @@
224
252
  });
225
253
  if (rendered) {
226
254
  thumbnailFile = rendered;
255
+ generatedThumbnail = rendered;
227
256
  thumbnailChanged = true;
228
257
  }
229
258
  }
259
+ // The default cover a new event gets without asking isn't worth losing the event over, so
260
+ // if it doesn't upload the event is saved without it. A cover the host chose, a preset as
261
+ // much as an image, fails the save instead, so it is never left out without their knowing.
262
+ const defaultCover =
263
+ isNew &&
264
+ !coverChosen &&
265
+ selectedPreset === DEFAULT_PRESET &&
266
+ thumbnailFile !== null &&
267
+ thumbnailFile === generatedThumbnail;
230
268
 
231
269
  const existingMedia = (eventData?.media ?? []) as Array<Record<string, unknown>>;
232
270
  const media = images
@@ -235,8 +273,15 @@
235
273
  thumbnailChanged,
236
274
  thumbnailFile,
237
275
  existingMedia,
238
- uploadBlob: (blob) =>
239
- adapter.uploadBlob(blob) as unknown as Promise<Record<string, unknown>>
276
+ uploadBlob: async (blob) => {
277
+ try {
278
+ return (await adapter.uploadBlob(blob)) as unknown as Record<string, unknown>;
279
+ } catch (e) {
280
+ if (!defaultCover) throw e;
281
+ console.warn('Generated cover not uploaded; saving the event without it:', e);
282
+ return null;
283
+ }
284
+ }
240
285
  })
241
286
  : existingMedia.length > 0
242
287
  ? existingMedia
@@ -342,7 +387,13 @@
342
387
  bind:thumbnailFile
343
388
  bind:thumbnailPreview
344
389
  bind:thumbnailChanged
345
- bind:selectedPreset
390
+ bind:selectedPreset={
391
+ () => selectedPreset,
392
+ (preset) => {
393
+ selectedPreset = preset;
394
+ coverChosen = true;
395
+ }
396
+ }
346
397
  />
347
398
  {/if}
348
399
 
@@ -439,7 +490,8 @@
439
490
  label="Event description"
440
491
  bind:value={description}
441
492
  markdown
442
- embeds
493
+ embeds={descriptionEmbeds}
494
+ socialClient={viewer.preferredSocialClient}
443
495
  placeholder="What's this event about? @mentions, #hashtags and links will be detected automatically."
444
496
  class="min-h-24 leading-relaxed text-base-700 focus-within:outline-none dark:text-base-300"
445
497
  />
@@ -1,3 +1,4 @@
1
+ import { type EventMediaUrl } from './event-media.js';
1
2
  import type { FlatEventRecord } from './contrail.js';
2
3
  import { type EventTheme } from './theme.js';
3
4
  import { type EventEditorPrefill } from './editor/types';
@@ -12,6 +13,8 @@ type $$ComponentProps = {
12
13
  initialTheme?: Partial<EventTheme>;
13
14
  /** Autofill payload for new events (e.g. imported from Luma/Meetup). */
14
15
  prefill?: EventEditorPrefill | null;
16
+ /** Where the editor loads the event's current image from; the public CDN by default. */
17
+ mediaUrl?: EventMediaUrl;
15
18
  };
16
19
  declare const EventEditor: import("svelte").Component<$$ComponentProps, {}, "">;
17
20
  type EventEditor = ReturnType<typeof EventEditor>;
@@ -2,7 +2,7 @@
2
2
  import { isEventOngoing, type AttendeeListLoader, type FlatEventRecord } from './contrail.js';
3
3
  import type { EventViewData } from './view-data.js';
4
4
  import { getCDNImageBlobUrl } from './atproto-helpers.js';
5
- import { getEventThumbnail, getEventExternalImage } from './event-media.js';
5
+ import { getEventThumbnail, getEventExternalImage, type EventMediaUrl } from './event-media.js';
6
6
  import { Button, ToggleGroup, ToggleGroupItem } from '../index.js';
7
7
  import ShareModal from './ShareModal.svelte';
8
8
  import EventComments from './EventComments.svelte';
@@ -48,7 +48,8 @@
48
48
  share = true,
49
49
  extraActions,
50
50
  attendeeActions,
51
- loadAttendees
51
+ loadAttendees,
52
+ mediaUrl = getCDNImageBlobUrl
52
53
  }: {
53
54
  data: EventViewData;
54
55
  adapter: EditorAdapter;
@@ -70,6 +71,8 @@
70
71
  /** Fetches the complete attendee lists the first time one is opened, when
71
72
  * `data.attendees` holds only a sample of the counted RSVPs. */
72
73
  loadAttendees?: AttendeeListLoader;
74
+ /** Where the page loads the event's own images from; the public CDN by default. */
75
+ mediaUrl?: EventMediaUrl;
73
76
  } = $props();
74
77
 
75
78
  let eventData: FlatEventRecord = $derived(data.eventData);
@@ -198,7 +201,7 @@
198
201
  if (!eventData.media || eventData.media.length === 0) return null;
199
202
  const media = getEventThumbnail(eventData.media);
200
203
  if (!media?.content) return null;
201
- const url = getCDNImageBlobUrl({ did, blob: media.content });
204
+ const url = mediaUrl({ did, blob: media.content });
202
205
  if (!url) return null;
203
206
  return { url, alt: media.alt || eventData.name, aspectRatio: media.aspect_ratio };
204
207
  });
@@ -207,7 +210,7 @@
207
210
  if (!eventData.media || eventData.media.length === 0) return null;
208
211
  const media = eventData.media.find((m) => m.role === 'header');
209
212
  if (!media?.content) return null;
210
- const url = getCDNImageBlobUrl({ did, blob: media.content });
213
+ const url = mediaUrl({ did, blob: media.content });
211
214
  if (!url) return null;
212
215
  return { url, alt: media.alt || eventData.name, aspectRatio: media.aspect_ratio };
213
216
  });
@@ -1,5 +1,6 @@
1
1
  import { type AttendeeListLoader } from './contrail.js';
2
2
  import type { EventViewData } from './view-data.js';
3
+ import { type EventMediaUrl } from './event-media.js';
3
4
  import { type AttendeeCounts } from './EventAttendees.svelte';
4
5
  import { type Snippet } from 'svelte';
5
6
  import type { EditorAdapter, EditorViewer } from './editor/adapter.js';
@@ -24,6 +25,8 @@ type $$ComponentProps = {
24
25
  /** Fetches the complete attendee lists the first time one is opened, when
25
26
  * `data.attendees` holds only a sample of the counted RSVPs. */
26
27
  loadAttendees?: AttendeeListLoader;
28
+ /** Where the page loads the event's own images from; the public CDN by default. */
29
+ mediaUrl?: EventMediaUrl;
27
30
  };
28
31
  declare const EventView: import("svelte").Component<$$ComponentProps, {}, "">;
29
32
  type EventView = ReturnType<typeof EventView>;
@@ -19,7 +19,8 @@ export declare function buildThumbnailMedia(args: {
19
19
  thumbnailChanged: boolean;
20
20
  thumbnailFile: File | null;
21
21
  existingMedia: Array<Record<string, unknown>>;
22
- uploadBlob: (blob: Blob) => Promise<Record<string, unknown>>;
22
+ /** Null leaves the new image out and keeps the media as it was. */
23
+ uploadBlob: (blob: Blob) => Promise<Record<string, unknown> | null>;
23
24
  }): Promise<Array<Record<string, unknown>> | undefined>;
24
25
  export declare function buildEventRecord(args: {
25
26
  eventData: FlatEventRecord | null;
@@ -1,3 +1,15 @@
1
+ /** The address of an image in an event's `media`, from the event's DID and the image's blob, or
2
+ * null to leave that image out. The components use the public CDN's (`getCDNImageBlobUrl`) unless
3
+ * a page supplies its own, as one must for an event whose pictures shouldn't reach a public CDN. */
4
+ export type EventMediaUrl = (image: {
5
+ did: string;
6
+ blob: {
7
+ $type: 'blob';
8
+ ref: {
9
+ $link: string;
10
+ };
11
+ };
12
+ }) => string | null;
1
13
  /** Select the event's thumbnail, falling back to a flyer before any header image. */
2
14
  export declare function getEventThumbnail<T extends {
3
15
  role?: unknown;
@@ -9,7 +9,7 @@ export * from './events/conference.js';
9
9
  export * from './events/linked-records.js';
10
10
  export * from './events/date-format.js';
11
11
  export * from './events/theme.js';
12
- export { getEventThumbnail, getEventExternalImage, type ExternalEventImage } from './events/event-media.js';
12
+ export { getEventThumbnail, getEventExternalImage, type EventMediaUrl, type ExternalEventImage } from './events/event-media.js';
13
13
  export { getCDNImageBlobUrl, compressImage, configureAtproto } from './events/atproto-helpers.js';
14
14
  export { getProfileUrl, getLocalProfileUrl } from './events/profile-url.js';
15
15
  export { resolveEventUrls, type EventUrls, type ResolvedEventUrls } from './events/urls.js';
@@ -1,6 +1,6 @@
1
- import { fromMarkdown } from 'mdast-util-from-markdown';
2
- import { gfmStrikethrough } from 'micromark-extension-gfm-strikethrough';
3
- import { gfmStrikethroughFromMarkdown } from 'mdast-util-gfm-strikethrough';
1
+ // The parser is bundled into the kit. Its packages' development builds need bundler setup in
2
+ // every app (they import CommonJS), and this is the same production build everywhere.
3
+ import { markdownTree } from './vendor/markdown-tree.js';
4
4
  import { safeWebUrl } from './document.js';
5
5
  import { applyRanges, detectLinks, hasFacets, resolveFacets } from './facets.js';
6
6
  import { parsePlainText } from './plain.js';
@@ -224,10 +224,7 @@ function collectDefinitions(node, definitions, depth = 0) {
224
224
  export function parseMarkdown(text, options = {}) {
225
225
  if (exceedsMarkdownLimits(text))
226
226
  return parsePlainText(text, options);
227
- const tree = fromMarkdown(text, {
228
- extensions: [gfmStrikethrough({ singleTilde: false })],
229
- mdastExtensions: [gfmStrikethroughFromMarkdown()]
230
- });
227
+ const tree = markdownTree(text);
231
228
  const definitions = new Map();
232
229
  collectDefinitions(tree, definitions);
233
230
  const context = {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * CommonMark plus ~~strikethrough~~, as an mdast `Root` with source positions. The parser is
3
+ * bundled here, so apps need no bundler configuration for it.
4
+ */
5
+ export function markdownTree(text: string): unknown;