@atmo-dev/kit 0.15.1 → 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.
@@ -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,6 +1,6 @@
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';
@@ -39,7 +39,8 @@
39
39
  adapter,
40
40
  viewer,
41
41
  initialTheme,
42
- prefill = null
42
+ prefill = null,
43
+ mediaUrl = getCDNImageBlobUrl
43
44
  }: {
44
45
  eventData: FlatEventRecord | null;
45
46
  actorDid: string;
@@ -50,6 +51,8 @@
50
51
  initialTheme?: Partial<EventTheme>;
51
52
  /** Autofill payload for new events (e.g. imported from Luma/Meetup). */
52
53
  prefill?: EventEditorPrefill | null;
54
+ /** Where the editor loads the event's current image from; the public CDN by default. */
55
+ mediaUrl?: EventMediaUrl;
53
56
  } = $props();
54
57
 
55
58
  let isNew = $derived(eventData === null);
@@ -96,6 +99,10 @@
96
99
  let selectedPreset: string | null = $state(
97
100
  initialThumbnailFile ? null : eventData === null ? DEFAULT_PRESET : null
98
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;
99
106
  let images = $derived(adapter.features.images !== false);
100
107
  const embedOptions = linkEmbedOptions();
101
108
  /** As on the event page: the app's embeds, plus cards for links to other events. */
@@ -159,7 +166,7 @@
159
166
  if (eventData.media && eventData.media.length > 0) {
160
167
  const media = getEventThumbnail(eventData.media);
161
168
  if (media?.content) {
162
- const url = getCDNImageBlobUrl({ did: actorDid, blob: media.content });
169
+ const url = mediaUrl({ did: actorDid, blob: media.content });
163
170
  if (url) {
164
171
  thumbnailPreview = url;
165
172
  thumbnailChanged = false;
@@ -245,9 +252,19 @@
245
252
  });
246
253
  if (rendered) {
247
254
  thumbnailFile = rendered;
255
+ generatedThumbnail = rendered;
248
256
  thumbnailChanged = true;
249
257
  }
250
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;
251
268
 
252
269
  const existingMedia = (eventData?.media ?? []) as Array<Record<string, unknown>>;
253
270
  const media = images
@@ -256,8 +273,15 @@
256
273
  thumbnailChanged,
257
274
  thumbnailFile,
258
275
  existingMedia,
259
- uploadBlob: (blob) =>
260
- 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
+ }
261
285
  })
262
286
  : existingMedia.length > 0
263
287
  ? existingMedia
@@ -363,7 +387,13 @@
363
387
  bind:thumbnailFile
364
388
  bind:thumbnailPreview
365
389
  bind:thumbnailChanged
366
- bind:selectedPreset
390
+ bind:selectedPreset={
391
+ () => selectedPreset,
392
+ (preset) => {
393
+ selectedPreset = preset;
394
+ coverChosen = true;
395
+ }
396
+ }
367
397
  />
368
398
  {/if}
369
399
 
@@ -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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atmo-dev/kit",
3
- "version": "0.15.1",
3
+ "version": "0.16.0",
4
4
  "description": "The shared UI foundation for Atmo apps.",
5
5
  "license": "MIT",
6
6
  "repository": {