@aphexcms/cms-core 11.1.0 → 11.1.1

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.
@@ -16,6 +16,7 @@
16
16
  * no image at all.
17
17
  */
18
18
  import { ImageOff } from '@lucide/svelte';
19
+ import type { Snippet } from 'svelte';
19
20
  import { browserCanDecodeImage } from '../../utils/image-support';
20
21
 
21
22
  interface Props {
@@ -29,9 +30,26 @@
29
30
  mimeType?: string | null;
30
31
  /** Caption under the placeholder icon. Omit in tiles too small to read it. */
31
32
  label?: string;
33
+ /**
34
+ * Rendered instead of the `ImageOff` placeholder when there is nothing to
35
+ * show. For an avatar or a logo the meaningful empty state is the initials
36
+ * block the surrounding component already draws when no image is set —
37
+ * falling back to it keeps a *failed* load looking like an *absent* one,
38
+ * rather than introducing a second, unrelated empty state.
39
+ */
40
+ fallback?: Snippet;
32
41
  }
33
42
 
34
- let { src, alt = '', class: className = '', style, loading, mimeType, label }: Props = $props();
43
+ let {
44
+ src,
45
+ alt = '',
46
+ class: className = '',
47
+ style,
48
+ loading,
49
+ mimeType,
50
+ label,
51
+ fallback
52
+ }: Props = $props();
35
53
 
36
54
  // Keyed by the src that failed rather than a bare boolean: pointing this
37
55
  // instance at a different asset must get a fresh attempt, or one broken image
@@ -42,16 +60,20 @@
42
60
  </script>
43
61
 
44
62
  {#if showPlaceholder}
45
- <div
46
- class="bg-muted/40 text-muted-foreground flex flex-col items-center justify-center gap-1 {className}"
47
- {style}
48
- title={label ?? alt}
49
- >
50
- <ImageOff class="h-4 w-4 shrink-0" />
51
- {#if label}
52
- <span class="px-2 text-center text-[10px] leading-tight">{label}</span>
53
- {/if}
54
- </div>
63
+ {#if fallback}
64
+ {@render fallback()}
65
+ {:else}
66
+ <div
67
+ class="bg-muted/40 text-muted-foreground flex flex-col items-center justify-center gap-1 {className}"
68
+ {style}
69
+ title={label ?? alt}
70
+ >
71
+ <ImageOff class="h-4 w-4 shrink-0" />
72
+ {#if label}
73
+ <span class="px-2 text-center text-[10px] leading-tight">{label}</span>
74
+ {/if}
75
+ </div>
76
+ {/if}
55
77
  {:else}
56
78
  <img {src} {alt} class={className} {style} {loading} onerror={() => (failedSrc = src ?? null)} />
57
79
  {/if}
@@ -1,3 +1,4 @@
1
+ import type { Snippet } from 'svelte';
1
2
  interface Props {
2
3
  src: string | null | undefined;
3
4
  alt?: string;
@@ -9,6 +10,14 @@ interface Props {
9
10
  mimeType?: string | null;
10
11
  /** Caption under the placeholder icon. Omit in tiles too small to read it. */
11
12
  label?: string;
13
+ /**
14
+ * Rendered instead of the `ImageOff` placeholder when there is nothing to
15
+ * show. For an avatar or a logo the meaningful empty state is the initials
16
+ * block the surrounding component already draws when no image is set —
17
+ * falling back to it keeps a *failed* load looking like an *absent* one,
18
+ * rather than introducing a second, unrelated empty state.
19
+ */
20
+ fallback?: Snippet;
12
21
  }
13
22
  declare const AssetImage: import("svelte").Component<Props, {}, "">;
14
23
  type AssetImage = ReturnType<typeof AssetImage>;
@@ -1 +1 @@
1
- {"version":3,"file":"AssetImage.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/components/admin/AssetImage.svelte.ts"],"names":[],"mappings":"AAuBC,UAAU,KAAK;IACd,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iFAAiF;IACjF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AA8BF,QAAA,MAAM,UAAU,2CAAwC,CAAC;AACzD,KAAK,UAAU,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AAChD,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"AssetImage.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/components/admin/AssetImage.svelte.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAIrC,UAAU,KAAK;IACd,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iFAAiF;IACjF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AA4CF,QAAA,MAAM,UAAU,2CAAwC,CAAC;AACzD,KAAK,UAAU,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AAChD,eAAe,UAAU,CAAC"}
@@ -17,6 +17,7 @@
17
17
  SidebarMenuButton,
18
18
  useSidebar
19
19
  } from '@aphexcms/ui/shadcn/sidebar';
20
+ import AssetImage from '../admin/AssetImage.svelte';
20
21
  import type { SidebarOrganization } from '../../types/sidebar';
21
22
  import { cn } from '../../utils';
22
23
  import { toast } from 'svelte-sonner';
@@ -120,22 +121,22 @@
120
121
  disabled={isSwitching}
121
122
  >
122
123
  {#if activeOrganization}
123
- {#if getOrganizationLogo(activeOrganization)}
124
- <img
125
- src={getOrganizationLogo(activeOrganization)!}
126
- alt={activeOrganization.name}
127
- class={cn(
128
- 'aspect-square size-8 object-cover',
129
- shouldInvertOrganizationLogo(activeOrganization) && 'dark:invert'
130
- )}
131
- />
132
- {:else}
124
+ {#snippet activeOrgInitials()}
133
125
  <div
134
126
  class="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg text-sm font-semibold"
135
127
  >
136
- {getOrganizationInitials(activeOrganization.name)}
128
+ {getOrganizationInitials(activeOrganization!.name)}
137
129
  </div>
138
- {/if}
130
+ {/snippet}
131
+ <AssetImage
132
+ src={getOrganizationLogo(activeOrganization)}
133
+ alt={activeOrganization.name}
134
+ class={cn(
135
+ 'aspect-square size-8 object-cover',
136
+ shouldInvertOrganizationLogo(activeOrganization) && 'dark:invert'
137
+ )}
138
+ fallback={activeOrgInitials}
139
+ />
139
140
  <div class="grid flex-1 text-left text-sm leading-tight">
140
141
  <span class="truncate font-medium">
141
142
  {activeOrganization.name}
@@ -185,22 +186,22 @@
185
186
  onclick={() => handleSwitchOrganization(org)}
186
187
  disabled={isSwitching}
187
188
  >
188
- {#if getOrganizationLogo(org)}
189
- <img
190
- src={getOrganizationLogo(org)!}
191
- alt={org.name}
192
- class={cn(
193
- 'size-8 shrink-0 rounded-md object-cover',
194
- shouldInvertOrganizationLogo(org) && 'dark:invert'
195
- )}
196
- />
197
- {:else}
189
+ {#snippet orgInitials()}
198
190
  <div
199
191
  class="bg-primary text-primary-foreground flex size-8 shrink-0 items-center justify-center rounded-md text-xs font-semibold"
200
192
  >
201
193
  {getOrganizationInitials(org.name)}
202
194
  </div>
203
- {/if}
195
+ {/snippet}
196
+ <AssetImage
197
+ src={getOrganizationLogo(org)}
198
+ alt={org.name}
199
+ class={cn(
200
+ 'size-8 shrink-0 rounded-md object-cover',
201
+ shouldInvertOrganizationLogo(org) && 'dark:invert'
202
+ )}
203
+ fallback={orgInitials}
204
+ />
204
205
  <div class="min-w-0 flex-1">
205
206
  <div class="flex items-center justify-between">
206
207
  <p class="truncate font-medium">{org.name}</p>
@@ -1 +1 @@
1
- {"version":3,"file":"OrganizationSwitcher.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/components/layout/OrganizationSwitcher.svelte.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAK9D,KAAK,KAAK,GAAG;IACZ,aAAa,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACtC,kBAAkB,CAAC,EAAE,mBAAmB,CAAC;IACzC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CACvC,CAAC;AAiMH,QAAA,MAAM,oBAAoB,2CAAwC,CAAC;AACnE,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACpE,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"OrganizationSwitcher.svelte.d.ts","sourceRoot":"","sources":["../../../src/lib/components/layout/OrganizationSwitcher.svelte.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAK9D,KAAK,KAAK,GAAG;IACZ,aAAa,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACtC,kBAAkB,CAAC,EAAE,mBAAmB,CAAC;IACzC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CACvC,CAAC;AAgMH,QAAA,MAAM,oBAAoB,2CAAwC,CAAC;AACnE,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACpE,eAAe,oBAAoB,CAAC"}
@@ -14,6 +14,7 @@
14
14
  DropdownMenuTrigger
15
15
  } from '@aphexcms/ui/shadcn/dropdown-menu';
16
16
  import { ChevronsUpDown, Settings, LogOut, Mail, Shield } from '@lucide/svelte';
17
+ import AssetImage from '../../admin/AssetImage.svelte';
17
18
  import type { SidebarUser } from '../../../types/sidebar';
18
19
 
19
20
  type Props = {
@@ -37,24 +38,30 @@
37
38
  <DropdownMenu>
38
39
  <DropdownMenuTrigger>
39
40
  {#snippet child({ props })}
41
+ <!-- Declared here, not inside SidebarMenuButton: a snippet that is a
42
+ direct child of a component is passed to it as a prop. -->
43
+ {#snippet userInitial()}
44
+ <div
45
+ class="bg-sidebar-primary text-sidebar-primary-foreground flex h-8 w-8 items-center justify-center rounded-lg text-sm font-semibold"
46
+ >
47
+ {user.name?.[0]?.toUpperCase() || user.email[0]?.toUpperCase()}
48
+ </div>
49
+ {/snippet}
40
50
  <SidebarMenuButton
41
51
  {...props}
42
52
  size="lg"
43
53
  class="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground cursor-pointer"
44
54
  >
45
- {#if user.image}
46
- <img
47
- src={user.image}
48
- alt={user.name || user.email}
49
- class="h-8 w-8 rounded-lg object-cover"
50
- />
51
- {:else}
52
- <div
53
- class="bg-sidebar-primary text-sidebar-primary-foreground flex h-8 w-8 items-center justify-center rounded-lg text-sm font-semibold"
54
- >
55
- {user.name?.[0]?.toUpperCase() || user.email[0]?.toUpperCase()}
56
- </div>
57
- {/if}
55
+ <!-- An avatar URL that 404s (a deleted upload, an expired remote
56
+ avatar) fell through to the browser's broken-image glyph. Route
57
+ it through AssetImage so a failed load lands on the same initials
58
+ block as no avatar at all. -->
59
+ <AssetImage
60
+ src={user.image}
61
+ alt={user.name || user.email}
62
+ class="h-8 w-8 rounded-lg object-cover"
63
+ fallback={userInitial}
64
+ />
58
65
  {#if sidebar.isMobile || sidebar.state !== 'collapsed'}
59
66
  <div class="grid flex-1 text-left text-sm leading-tight">
60
67
  <span class="truncate font-medium">{user.name || user.email}</span>
@@ -1 +1 @@
1
- {"version":3,"file":"NavUser.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/layout/sidebar/NavUser.svelte.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGzD,KAAK,KAAK,GAAG;IACZ,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC,CAAC;AA2EH,QAAA,MAAM,OAAO,2CAAwC,CAAC;AACtD,KAAK,OAAO,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC;AAC1C,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"NavUser.svelte.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/layout/sidebar/NavUser.svelte.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGzD,KAAK,KAAK,GAAG;IACZ,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC,CAAC;AA6EH,QAAA,MAAM,OAAO,2CAAwC,CAAC;AACtD,KAAK,OAAO,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC;AAC1C,eAAe,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aphexcms/cms-core",
3
- "version": "11.1.0",
3
+ "version": "11.1.1",
4
4
  "description": "Aphex CMS Core - A Sanity-style CMS with ports and adapters architecture",
5
5
  "publishConfig": {
6
6
  "access": "public",