@atmo-dev/kit 0.16.0 → 0.18.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,12 +1,22 @@
1
- <script lang="ts">
1
+ <script lang="ts" module>
2
2
  import { DropdownMenu } from 'bits-ui';
3
- import { UserRound, LogOut } from '@sketchyicons/svelte';
3
+ import { UserRound, UserRoundPlus, LogOut } from '@sketchyicons/svelte';
4
4
  import Avatar from './Avatar.svelte';
5
5
  import Button from './Button.svelte';
6
6
  import Icon from './Icon.svelte';
7
7
  import { cn } from '../utils.js';
8
8
  import { readTheme, observeTheme } from '../theme.js';
9
9
 
10
+ /** Another signed-in account that can be switched to. `did` identifies it; the rest is display only. */
11
+ export type AccountMenuAccount = {
12
+ did: string;
13
+ name?: string;
14
+ handle?: string;
15
+ avatar?: string;
16
+ };
17
+ </script>
18
+
19
+ <script lang="ts">
10
20
  let {
11
21
  name,
12
22
  handle,
@@ -14,6 +24,9 @@
14
24
  profileHref,
15
25
  onprofile,
16
26
  onsignout,
27
+ accounts = [],
28
+ onswitch,
29
+ onadd,
17
30
  expanded = false,
18
31
  open = $bindable(false),
19
32
  label = 'Account menu',
@@ -23,6 +36,11 @@
23
36
  handle?: string;
24
37
  avatar?: string;
25
38
  onsignout: () => void;
39
+ /** Other signed-in accounts, without the current one. */
40
+ accounts?: AccountMenuAccount[];
41
+ onswitch?: (did: string) => void;
42
+ /** Shows "Add account" when provided. */
43
+ onadd?: () => void;
26
44
  expanded?: boolean;
27
45
  open?: boolean;
28
46
  label?: string;
@@ -42,6 +60,8 @@
42
60
  });
43
61
  const itemClass =
44
62
  'min-h-11 w-full justify-start gap-3 px-3 text-sm text-base-950 dark:text-base-50 outline-none data-highlighted:bg-[color-mix(in_srgb,var(--base-100)_75%,var(--base-200))] dark:data-highlighted:bg-base-950 data-highlighted:text-base-950 dark:data-highlighted:text-base-50';
63
+ const separatorClass =
64
+ '-mx-1.5 my-1.5 h-px bg-base-300 dark:bg-[color-mix(in_srgb,var(--base-800)_80%,var(--base-950))]';
45
65
  </script>
46
66
 
47
67
  <DropdownMenu.Root bind:open>
@@ -90,6 +110,48 @@
90
110
  </Button>
91
111
  {/snippet}
92
112
  </DropdownMenu.Item>
113
+ {#if onswitch && accounts.length}
114
+ <DropdownMenu.Separator class={separatorClass} />
115
+ <DropdownMenu.Group aria-label="Switch account">
116
+ {#each accounts as account (account.did)}
117
+ {@const handle = account.handle?.replace(/^@/, '')}
118
+ {@const title = account.name || handle || account.did}
119
+ <DropdownMenu.Item onSelect={() => onswitch(account.did)} textValue={title}>
120
+ {#snippet child({ props })}
121
+ <Button
122
+ {...props}
123
+ variant="ghost"
124
+ aria-label={`Switch to ${title}`}
125
+ class={cn(itemClass, 'py-1.5')}
126
+ >
127
+ <Avatar name={title} src={account.avatar} size={20} aria-hidden="true" />
128
+ <span class="min-w-0 text-left">
129
+ <span class="block truncate">{title}</span>
130
+ {#if handle && handle !== title}<span
131
+ class="block truncate text-xs text-base-600 dark:text-base-400"
132
+ >@{handle}</span
133
+ >{/if}
134
+ </span>
135
+ </Button>
136
+ {/snippet}
137
+ </DropdownMenu.Item>
138
+ {/each}
139
+ </DropdownMenu.Group>
140
+ {/if}
141
+ {#if onadd}
142
+ {#if !(onswitch && accounts.length)}<DropdownMenu.Separator class={separatorClass} />{/if}
143
+ <DropdownMenu.Item onSelect={onadd} textValue="Add account">
144
+ {#snippet child({ props })}
145
+ <Button {...props} variant="ghost" class={itemClass}>
146
+ <Icon img={UserRoundPlus} size={20} class="text-base-600 dark:text-base-400" />Add
147
+ account
148
+ </Button>
149
+ {/snippet}
150
+ </DropdownMenu.Item>
151
+ {/if}
152
+ {#if onadd || (onswitch && accounts.length)}
153
+ <DropdownMenu.Separator class={separatorClass} />
154
+ {/if}
93
155
  <DropdownMenu.Item onSelect={onsignout} textValue="Sign out">
94
156
  {#snippet child({ props })}
95
157
  <Button {...props} variant="ghost" class={itemClass}>
@@ -1,8 +1,20 @@
1
+ /** Another signed-in account that can be switched to. `did` identifies it; the rest is display only. */
2
+ export type AccountMenuAccount = {
3
+ did: string;
4
+ name?: string;
5
+ handle?: string;
6
+ avatar?: string;
7
+ };
1
8
  type $$ComponentProps = {
2
9
  name: string;
3
10
  handle?: string;
4
11
  avatar?: string;
5
12
  onsignout: () => void;
13
+ /** Other signed-in accounts, without the current one. */
14
+ accounts?: AccountMenuAccount[];
15
+ onswitch?: (did: string) => void;
16
+ /** Shows "Add account" when provided. */
17
+ onadd?: () => void;
6
18
  expanded?: boolean;
7
19
  open?: boolean;
8
20
  label?: string;
@@ -40,7 +40,10 @@
40
40
  viewer,
41
41
  initialTheme,
42
42
  prefill = null,
43
- mediaUrl = getCDNImageBlobUrl
43
+ mediaUrl = getCDNImageBlobUrl,
44
+ visibility = $bindable('public'),
45
+ visibilityOptions = ['public', 'unlisted'],
46
+ confirmVisibility
44
47
  }: {
45
48
  eventData: FlatEventRecord | null;
46
49
  actorDid: string;
@@ -53,6 +56,12 @@
53
56
  prefill?: EventEditorPrefill | null;
54
57
  /** Where the editor loads the event's current image from; the public CDN by default. */
55
58
  mediaUrl?: EventMediaUrl;
59
+ /** Who can see the event. Bind it to follow the host's choice; an existing event's record sets it. */
60
+ visibility?: Visibility;
61
+ /** The choices the switch offers, in order. Public and Unlisted by default. */
62
+ visibilityOptions?: readonly Visibility[];
63
+ /** Asked before the choice changes; returning false keeps the current one. */
64
+ confirmVisibility?: (next: Visibility) => boolean | Promise<boolean>;
56
65
  } = $props();
57
66
 
58
67
  let isNew = $derived(eventData === null);
@@ -79,7 +88,6 @@
79
88
  );
80
89
  let timezone = $state(initialTimezone);
81
90
  let mode: EventMode = $state(initialPrefill?.mode ?? 'inperson');
82
- let visibility: Visibility = $state('public');
83
91
  // svelte-ignore state_referenced_locally
84
92
  let eventTheme: EventTheme = $state(
85
93
  eventData === null
@@ -124,6 +132,16 @@
124
132
  ];
125
133
  });
126
134
  let showVisibility = $derived(adapter.features.visibility !== false);
135
+ const VISIBILITY_LABELS: Record<Visibility, string> = {
136
+ public: 'Public',
137
+ unlisted: 'Unlisted',
138
+ private: 'Private'
139
+ };
140
+ async function chooseVisibility(next: Visibility) {
141
+ if (next === visibility) return;
142
+ if (confirmVisibility && !(await confirmVisibility(next))) return;
143
+ visibility = next;
144
+ }
127
145
  let submitting = $state(false);
128
146
  let error: string | null = $state(null);
129
147
  let titleEditor = $state<Editor | null>(null);
@@ -438,20 +456,23 @@
438
456
  bind:value={
439
457
  () => visibility,
440
458
  (val) => {
441
- if (val) visibility = val as Visibility;
459
+ if (val) void chooseVisibility(val as Visibility);
442
460
  }
443
461
  }
444
462
  class="w-fit"
445
463
  size="xs"
446
464
  >
447
- <ToggleGroupItem value="public">Public</ToggleGroupItem>
448
- <ToggleGroupItem value="unlisted">Unlisted</ToggleGroupItem>
465
+ {#each visibilityOptions as option (option)}
466
+ <ToggleGroupItem value={option}>{VISIBILITY_LABELS[option]}</ToggleGroupItem>
467
+ {/each}
449
468
  </ToggleGroup>
450
469
  <div class="mt-1.5 text-xs text-base-600 dark:text-base-400">
451
470
  {#if visibility === 'public'}
452
471
  Anyone can view and it appears in discovery.
453
- {:else}
472
+ {:else if visibility === 'unlisted'}
454
473
  Public to anyone with the link, but hidden from discovery.
474
+ {:else}
475
+ Only people you invite can see it.
455
476
  {/if}
456
477
  </div>
457
478
  </div>
@@ -1,7 +1,7 @@
1
1
  import { type EventMediaUrl } from './event-media.js';
2
2
  import type { FlatEventRecord } from './contrail.js';
3
3
  import { type EventTheme } from './theme.js';
4
- import { type EventEditorPrefill } from './editor/types';
4
+ import { type EventEditorPrefill, type Visibility } from './editor/types';
5
5
  import type { EditorAdapter, EditorViewer } from './editor/adapter';
6
6
  type $$ComponentProps = {
7
7
  eventData: FlatEventRecord | null;
@@ -15,7 +15,13 @@ type $$ComponentProps = {
15
15
  prefill?: EventEditorPrefill | null;
16
16
  /** Where the editor loads the event's current image from; the public CDN by default. */
17
17
  mediaUrl?: EventMediaUrl;
18
+ /** Who can see the event. Bind it to follow the host's choice; an existing event's record sets it. */
19
+ visibility?: Visibility;
20
+ /** The choices the switch offers, in order. Public and Unlisted by default. */
21
+ visibilityOptions?: readonly Visibility[];
22
+ /** Asked before the choice changes; returning false keeps the current one. */
23
+ confirmVisibility?: (next: Visibility) => boolean | Promise<boolean>;
18
24
  };
19
- declare const EventEditor: import("svelte").Component<$$ComponentProps, {}, "">;
25
+ declare const EventEditor: import("svelte").Component<$$ComponentProps, {}, "visibility">;
20
26
  type EventEditor = ReturnType<typeof EventEditor>;
21
27
  export default EventEditor;
@@ -43,8 +43,8 @@ export type EditorAdapter = {
43
43
  */
44
44
  images?: boolean;
45
45
  /**
46
- * False for an event with no public listing to appear in: no Public / Unlisted switch, and
47
- * the record's discovery preference is left as it is.
46
+ * False for an event with no public listing to appear in: no visibility switch, and the
47
+ * record's discovery preference is left as it is.
48
48
  */
49
49
  visibility?: boolean;
50
50
  };
@@ -158,13 +158,14 @@ export async function buildEventRecord(args) {
158
158
  if (Array.isArray(record.locations)) {
159
159
  record.locations = normalizeEventLocations(record.locations);
160
160
  }
161
- // With no Public / Unlisted choice offered, the record keeps whatever preference it had.
161
+ // With no visibility choice offered, the record keeps whatever preference it had. Only a public
162
+ // event appears in discovery.
162
163
  if (visibility !== null) {
163
164
  const existingPrefs = (record.preferences ??
164
165
  {});
165
166
  record.preferences = {
166
167
  ...existingPrefs,
167
- showInDiscovery: visibility !== 'unlisted'
168
+ showInDiscovery: visibility === 'public'
168
169
  };
169
170
  }
170
171
  return record;
@@ -1,5 +1,5 @@
1
1
  export type EventMode = 'inperson' | 'virtual' | 'hybrid';
2
- export type Visibility = 'public' | 'unlisted';
2
+ export type Visibility = 'public' | 'unlisted' | 'private';
3
3
  export interface EventLocation {
4
4
  street?: string;
5
5
  locality?: string;
@@ -1,7 +1,7 @@
1
1
  /** Event types and pure helpers. Safe to import without Svelte, CSS or browser players. */
2
2
  export type { EventViewData } from './events/view-data.js';
3
3
  export type { EditorAdapter, EditorBlobRef, EditorViewer } from './events/editor/adapter.js';
4
- export type { EventEditorPrefill } from './events/editor/types.js';
4
+ export type { EventEditorPrefill, Visibility as EventVisibility } from './events/editor/types.js';
5
5
  export type { EventData, EventLexiconMain, EventLocationVariant, EventStatus, EventMode as EventLexiconMode } from './events/event-types.js';
6
6
  export type { FlatEventRecord, HostProfile, AttendeeInfo, AttendeeListLoader } from './events/contrail.js';
7
7
  export { eventUrl, isEventOngoing, RSVP_GOING, RSVP_INTERESTED } from './events/contrail.js';
package/dist/index.d.ts CHANGED
@@ -65,6 +65,7 @@ export { default as IconRail } from './components/IconRail.svelte';
65
65
  export type { IconRailItem } from './components/IconRail.svelte';
66
66
  export { default as WorkspaceSidebar } from './components/WorkspaceSidebar.svelte';
67
67
  export { default as AccountMenu } from './components/AccountMenu.svelte';
68
+ export type { AccountMenuAccount } from './components/AccountMenu.svelte';
68
69
  export { default as LoginForm } from './components/login/LoginForm.svelte';
69
70
  export type { LoginFormProps } from './components/login/LoginForm.svelte';
70
71
  export { default as LoginDialog } from './components/login/LoginDialog.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atmo-dev/kit",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "The shared UI foundation for Atmo apps.",
5
5
  "license": "MIT",
6
6
  "repository": {