@glasshome/ui 1.21.1 → 1.21.2
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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/use-is-mobile.d.ts +3 -1
- package/dist/solid/index.d.ts +9 -9
- package/dist/solid/index.js +5431 -5424
- package/dist/{utils-CMk7R3zM.js → utils-D5blHO4O.js} +624 -622
- package/package.json +128 -126
- package/scripts/check-gallery.ts +142 -142
- package/scripts/check-pack.ts +13 -13
- package/scripts/check-structural-classes.ts +20 -20
- package/scripts/check-tokens.ts +27 -27
- package/scripts/check-ui-drift.mjs +103 -103
- package/src/index.ts +75 -80
- package/src/lib/alert-tones.ts +41 -41
- package/src/lib/anchor-placement.ts +21 -21
- package/src/lib/button-variants.ts +28 -28
- package/src/lib/card-classes.ts +9 -9
- package/src/lib/carousel-classes.ts +14 -14
- package/src/lib/glass-tone.ts +11 -11
- package/src/lib/input-classes.ts +6 -6
- package/src/lib/layers.ts +4 -4
- package/src/lib/logo-lockup.ts +8 -8
- package/src/lib/menu-classes.ts +2 -2
- package/src/lib/motion-classes.ts +8 -8
- package/src/lib/motion-window.ts +24 -24
- package/src/lib/overlay-classes.ts +6 -6
- package/src/lib/pill-classes.ts +3 -3
- package/src/lib/position-bar-classes.ts +1 -1
- package/src/lib/spotlight-geometry.ts +67 -67
- package/src/lib/thumb-classes.ts +2 -2
- package/src/lib/tier-badge.ts +16 -16
- package/src/lib/use-is-mobile.ts +17 -14
- package/src/lib/utils.ts +1 -1
- package/src/solid/accordion.tsx +41 -41
- package/src/solid/alert-dialog.tsx +95 -95
- package/src/solid/alert.tsx +88 -88
- package/src/solid/area-picker.tsx +204 -204
- package/src/solid/aspect-ratio.tsx +13 -13
- package/src/solid/avatar.tsx +27 -27
- package/src/solid/badge.tsx +49 -49
- package/src/solid/bottom-sheet/arbitration.ts +22 -22
- package/src/solid/bottom-sheet/bottom-sheet.tsx +394 -394
- package/src/solid/bottom-sheet/drag-controller.ts +201 -201
- package/src/solid/bottom-sheet/focus-trap.ts +51 -47
- package/src/solid/bottom-sheet/index.ts +12 -12
- package/src/solid/bottom-sheet/keyboard.ts +25 -25
- package/src/solid/bottom-sheet/scroll-lock.ts +46 -46
- package/src/solid/bottom-sheet/state-machine.ts +28 -28
- package/src/solid/bottom-sheet/velocity.ts +29 -29
- package/src/solid/breadcrumb.tsx +76 -76
- package/src/solid/button-group.tsx +46 -46
- package/src/solid/button.tsx +19 -19
- package/src/solid/card.tsx +67 -67
- package/src/solid/carousel.tsx +246 -246
- package/src/solid/charts.tsx +253 -253
- package/src/solid/checkbox.tsx +51 -51
- package/src/solid/collapsible.tsx +22 -22
- package/src/solid/color-disc.tsx +213 -213
- package/src/solid/color-slider.tsx +81 -81
- package/src/solid/color-wheel.tsx +61 -61
- package/src/solid/context-menu.tsx +63 -63
- package/src/solid/copy-button.tsx +31 -31
- package/src/solid/count-pill.tsx +11 -11
- package/src/solid/dashboard-preview.tsx +104 -104
- package/src/solid/data-table.tsx +228 -228
- package/src/solid/dialog-parts.tsx +127 -127
- package/src/solid/dialog.tsx +113 -113
- package/src/solid/dock-paging.ts +9 -9
- package/src/solid/dock.tsx +339 -339
- package/src/solid/docked-panel.tsx +35 -35
- package/src/solid/dropdown-menu.tsx +77 -77
- package/src/solid/empty.tsx +70 -70
- package/src/solid/entity-data.ts +38 -38
- package/src/solid/entity-selector.tsx +634 -634
- package/src/solid/field.tsx +205 -205
- package/src/solid/form.tsx +159 -159
- package/src/solid/hero-action.tsx +85 -85
- package/src/solid/hover-card.tsx +11 -11
- package/src/solid/icon-picker.tsx +401 -401
- package/src/solid/icon.tsx +101 -78
- package/src/solid/image-picker.tsx +416 -414
- package/src/solid/index.ts +265 -304
- package/src/solid/input-group.tsx +123 -123
- package/src/solid/input-otp.tsx +143 -143
- package/src/solid/input.tsx +4 -4
- package/src/solid/item.tsx +130 -130
- package/src/solid/kbd.tsx +20 -20
- package/src/solid/label.tsx +12 -12
- package/src/solid/list-reorder.ts +122 -122
- package/src/solid/logo.tsx +60 -60
- package/src/solid/media-copy.ts +21 -21
- package/src/solid/media-store.ts +56 -56
- package/src/solid/media-tile.tsx +85 -85
- package/src/solid/menu-parts.tsx +164 -164
- package/src/solid/number-field.tsx +56 -56
- package/src/solid/option-card.tsx +164 -164
- package/src/solid/ornament.tsx +43 -43
- package/src/solid/overlay.tsx +4 -4
- package/src/solid/page-header.tsx +75 -75
- package/src/solid/pagination.tsx +80 -80
- package/src/solid/password-input.tsx +51 -51
- package/src/solid/picker-row.tsx +83 -83
- package/src/solid/picker-search.tsx +65 -63
- package/src/solid/picker-trigger.tsx +59 -57
- package/src/solid/popover.tsx +54 -54
- package/src/solid/preview-tile.tsx +67 -67
- package/src/solid/progress.tsx +21 -21
- package/src/solid/radio-group.tsx +51 -51
- package/src/solid/resizable.tsx +128 -128
- package/src/solid/responsive-dialog.tsx +134 -134
- package/src/solid/schema-form.tsx +743 -743
- package/src/solid/scope-indicator.tsx +5 -5
- package/src/solid/scroll-area.tsx +16 -16
- package/src/solid/section-card.tsx +281 -281
- package/src/solid/select.tsx +101 -101
- package/src/solid/separator.tsx +25 -25
- package/src/solid/settings-row.tsx +122 -122
- package/src/solid/sheet.tsx +96 -96
- package/src/solid/skeleton.tsx +8 -8
- package/src/solid/slider.tsx +132 -132
- package/src/solid/sliding-indicator.tsx +280 -265
- package/src/solid/sonner.tsx +164 -164
- package/src/solid/spinner.tsx +12 -12
- package/src/solid/spotlight.tsx +140 -140
- package/src/solid/step-indicator.tsx +18 -18
- package/src/solid/swatch-picker.tsx +38 -38
- package/src/solid/switch.tsx +52 -52
- package/src/solid/table.tsx +63 -63
- package/src/solid/tabs.tsx +93 -93
- package/src/solid/textarea.tsx +8 -8
- package/src/solid/toggle-group.tsx +83 -83
- package/src/solid/toggle.tsx +33 -33
- package/src/solid/tooltip.tsx +16 -16
- package/src/solid/widget-card.tsx +90 -90
- package/src/solid/widget-identity.tsx +99 -99
- package/src/solid/widget-trust-badge.tsx +20 -20
- package/src/styles/globals.css +316 -319
- package/src/styles/theme.css +448 -448
- package/src/tokens/hex.ts +29 -29
- package/src/tokens/material.ts +75 -75
- package/src/tokens/presets.ts +303 -303
- package/src/tokens/readability.ts +32 -32
- package/src/tokens/theme-colors.ts +95 -95
- package/src/tokens/theme-css.ts +22 -22
- package/src/tokens/theme-recipe.ts +106 -106
package/src/solid/logo.tsx
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { type Component, type ComponentProps, type JSX, splitProps } from "solid-js";
|
|
2
2
|
import { Dynamic } from "solid-js/web";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
LOGO_DEFAULT_SIZE,
|
|
5
|
+
LOGO_DEFAULT_SRC,
|
|
6
|
+
LOGO_DEFAULT_SUB,
|
|
7
|
+
LOGO_MARK_CLASS,
|
|
8
|
+
LOGO_MARK_PX,
|
|
9
|
+
LOGO_NAME_CLASS,
|
|
10
|
+
LOGO_ROOT_CLASS,
|
|
11
|
+
LOGO_SIZES,
|
|
12
|
+
LOGO_STACK_CLASS,
|
|
13
|
+
LOGO_SUB_CLASS,
|
|
14
|
+
type LogoSize,
|
|
15
15
|
} from "../lib/logo-lockup.js";
|
|
16
16
|
import { cn } from "../lib/utils.js";
|
|
17
17
|
|
|
18
18
|
type LogoProps = Omit<ComponentProps<"div">, "children"> & {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
/** Sub-brand line. Defaults to "Dash". */
|
|
20
|
+
sub?: string;
|
|
21
|
+
size?: LogoSize;
|
|
22
|
+
/** Renders the lockup as a link when set. */
|
|
23
|
+
href?: string;
|
|
24
|
+
/** Override the mark asset. Both apps serve the default path. */
|
|
25
|
+
src?: string;
|
|
26
|
+
/** Extra classes for the mark, e.g. a hover transform. */
|
|
27
|
+
markClass?: string;
|
|
28
|
+
/** Replaces the sub-brand line for surfaces that animate over it. */
|
|
29
|
+
subSlot?: JSX.Element;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -36,44 +36,44 @@ type LogoProps = Omit<ComponentProps<"div">, "children"> & {
|
|
|
36
36
|
* Never hand-build this stack; the spec lives in lib/logo-lockup.ts.
|
|
37
37
|
*/
|
|
38
38
|
const Logo: Component<LogoProps> = (props) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
39
|
+
const [local, others] = splitProps(props, [
|
|
40
|
+
"class",
|
|
41
|
+
"sub",
|
|
42
|
+
"size",
|
|
43
|
+
"href",
|
|
44
|
+
"src",
|
|
45
|
+
"markClass",
|
|
46
|
+
"subSlot",
|
|
47
|
+
]);
|
|
48
|
+
const size = () => local.size ?? LOGO_DEFAULT_SIZE;
|
|
49
|
+
const s = () => LOGO_SIZES[size()];
|
|
50
|
+
return (
|
|
51
|
+
<Dynamic
|
|
52
|
+
component={local.href ? "a" : "div"}
|
|
53
|
+
data-slot="logo"
|
|
54
|
+
class={cn(LOGO_ROOT_CLASS, s().gap, local.class)}
|
|
55
|
+
href={local.href}
|
|
56
|
+
{...others}
|
|
57
|
+
>
|
|
58
|
+
<img
|
|
59
|
+
src={local.src ?? LOGO_DEFAULT_SRC}
|
|
60
|
+
alt=""
|
|
61
|
+
width={LOGO_MARK_PX[size()]}
|
|
62
|
+
height={LOGO_MARK_PX[size()]}
|
|
63
|
+
class={cn(LOGO_MARK_CLASS, s().mark, local.markClass)}
|
|
64
|
+
/>
|
|
65
|
+
<span class={LOGO_STACK_CLASS}>
|
|
66
|
+
<span data-slot="logo-name" class={cn(s().name, LOGO_NAME_CLASS)}>
|
|
67
|
+
GlassHome
|
|
68
|
+
</span>
|
|
69
|
+
{local.subSlot ?? (
|
|
70
|
+
<span data-slot="logo-sub" class={cn(s().sub, LOGO_SUB_CLASS)}>
|
|
71
|
+
{local.sub ?? LOGO_DEFAULT_SUB}
|
|
72
|
+
</span>
|
|
73
|
+
)}
|
|
74
|
+
</span>
|
|
75
|
+
</Dynamic>
|
|
76
|
+
);
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
export { Logo };
|
package/src/solid/media-copy.ts
CHANGED
|
@@ -4,34 +4,34 @@ import { type MediaQuotaUsage, MediaStoreError, type MediaStoreErrorKind } from
|
|
|
4
4
|
/** One table for every surface that shows a media failure: the picker, the settings
|
|
5
5
|
* section, the library. Two tables drifted apart once already. */
|
|
6
6
|
const STORE_ERROR_COPY: Record<MediaStoreErrorKind, (usage?: MediaQuotaUsage) => string> = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
file_too_large: () => "That file is too large to upload.",
|
|
8
|
+
image_too_large: () => "That image's dimensions are too large.",
|
|
9
|
+
not_an_image: () => "That file isn't an image.",
|
|
10
|
+
quota_bytes_exceeded: (usage) =>
|
|
11
|
+
usage
|
|
12
|
+
? `You've used ${formatBytes(usage.bytes)} of ${formatBytes(usage.limitBytes)} of photo storage. Delete a photo to free up space.`
|
|
13
|
+
: "You're out of photo storage. Delete a photo to free up space.",
|
|
14
|
+
quota_files_exceeded: (usage) =>
|
|
15
|
+
usage
|
|
16
|
+
? `You've stored ${usage.files} of ${usage.limitFiles} photos. Delete one to add another.`
|
|
17
|
+
: "You've reached the photo limit. Delete one to add another.",
|
|
18
|
+
upload_rate_exceeded: () => "Too many uploads at once. Wait a moment and try again.",
|
|
19
|
+
server_storage_full: () =>
|
|
20
|
+
"The dashboard's photo storage is full. Whoever runs this dashboard needs to free up space on the server.",
|
|
21
|
+
no_active_household: () => "No household is active, so photos can't be stored right now.",
|
|
22
|
+
upload_failed: () => "That didn't work. Try again, and sign in again if it keeps failing.",
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
export function toMediaStoreError(cause: unknown): MediaStoreError {
|
|
26
|
-
|
|
26
|
+
return cause instanceof MediaStoreError ? cause : new MediaStoreError("upload_failed");
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function mediaStoreErrorCopy(error: MediaStoreError): string {
|
|
30
|
-
|
|
30
|
+
return STORE_ERROR_COPY[error.kind](error.usage);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export function mediaIndexErrorCopy(error: MediaStoreError): string {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
return error.kind === "no_active_household"
|
|
35
|
+
? "No household is active, so your photos can't be listed right now."
|
|
36
|
+
: "Your photos couldn't be listed. The dashboard may have lost the server.";
|
|
37
37
|
}
|
package/src/solid/media-store.ts
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
1
|
import { createContext, createSignal, useContext } from "solid-js";
|
|
2
2
|
|
|
3
3
|
export type StoredMedia = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
id: string;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
size: number;
|
|
9
|
+
/** Server-computed count of live widget configs referencing this id. */
|
|
10
|
+
usedBy: number;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export type MediaQuotaUsage = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
bytes: number;
|
|
15
|
+
limitBytes: number;
|
|
16
|
+
files: number;
|
|
17
|
+
limitFiles: number;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export type MediaStoreErrorKind =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
| "file_too_large"
|
|
22
|
+
| "image_too_large"
|
|
23
|
+
| "not_an_image"
|
|
24
|
+
| "quota_bytes_exceeded"
|
|
25
|
+
| "quota_files_exceeded"
|
|
26
|
+
| "upload_rate_exceeded"
|
|
27
|
+
| "server_storage_full"
|
|
28
|
+
| "no_active_household"
|
|
29
|
+
| "upload_failed";
|
|
30
30
|
|
|
31
31
|
export class MediaStoreError extends Error {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
readonly kind: MediaStoreErrorKind;
|
|
33
|
+
readonly usage?: MediaQuotaUsage;
|
|
34
|
+
|
|
35
|
+
constructor(kind: MediaStoreErrorKind, usage?: MediaQuotaUsage) {
|
|
36
|
+
super(kind);
|
|
37
|
+
this.name = "MediaStoreError";
|
|
38
|
+
this.kind = kind;
|
|
39
|
+
this.usage = usage;
|
|
40
|
+
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/** One gallery open, one query: the server counts usage in the same scan. */
|
|
44
44
|
export type MediaIndex = {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
media: StoredMedia[];
|
|
46
|
+
usage: MediaQuotaUsage;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
/** "thumb" is a server-side derivative, longest edge ~400px, for grids. */
|
|
50
50
|
export type MediaVariant = "original" | "thumb";
|
|
51
51
|
|
|
52
52
|
export interface MediaStore {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
index(): Promise<MediaIndex>;
|
|
54
|
+
upload(file: File): Promise<StoredMedia>;
|
|
55
|
+
remove(id: string): Promise<void>;
|
|
56
|
+
url(id: string, variant?: MediaVariant): string;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export const MediaStoreContext = createContext<MediaStore>();
|
|
@@ -62,11 +62,11 @@ let defaultStore: MediaStore | undefined;
|
|
|
62
62
|
|
|
63
63
|
/** Host apps call this once at startup; MediaStoreContext overrides it per-tree. */
|
|
64
64
|
export function provideMediaStore(store: MediaStore): void {
|
|
65
|
-
|
|
65
|
+
defaultStore = store;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export function useMediaStore(): MediaStore | undefined {
|
|
69
|
-
|
|
69
|
+
return useContext(MediaStoreContext) ?? defaultStore;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/** One grid page. The picker and the library both slice by this, so neither can
|
|
@@ -76,53 +76,53 @@ export const MEDIA_PAGE_SIZE = 24;
|
|
|
76
76
|
/** A row whose mime is missing or not a string is not an image; a throw here would
|
|
77
77
|
* take the surrounding gallery down with it. */
|
|
78
78
|
export function isMediaImage(item: StoredMedia): boolean {
|
|
79
|
-
|
|
79
|
+
return typeof item.mimeType === "string" && item.mimeType.startsWith("image/");
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/** Unused first: someone browsing stored media is looking for what is safe to delete. */
|
|
83
83
|
export function sortMediaForClearing(media: StoredMedia[]): StoredMedia[] {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
return media.filter(isMediaImage).sort((a, b) => {
|
|
85
|
+
if ((a.usedBy === 0) !== (b.usedBy === 0)) return a.usedBy === 0 ? -1 : 1;
|
|
86
|
+
return a.id.localeCompare(b.id);
|
|
87
|
+
});
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
export interface BrokenMedia {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
isBroken: (item: StoredMedia) => boolean;
|
|
92
|
+
markBroken: (item: StoredMedia) => void;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/** Keyed by the url that failed, so a re-uploaded id (new url) starts unbroken again. */
|
|
96
96
|
export function createBrokenMedia(thumbUrl: (id: string) => string): BrokenMedia {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
const [broken, setBroken] = createSignal<Readonly<Record<string, string>>>({});
|
|
98
|
+
return {
|
|
99
|
+
isBroken: (item) => broken()[item.id] === thumbUrl(item.id),
|
|
100
|
+
markBroken: (item) => setBroken((previous) => ({ ...previous, [item.id]: thumbUrl(item.id) })),
|
|
101
|
+
};
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
const PRESET_PREFIX = "preset:";
|
|
105
105
|
|
|
106
106
|
/** A built-in picture a widget offers beside the household's own uploads. */
|
|
107
107
|
export interface ImagePreset {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
label: string;
|
|
109
|
+
/** Small image for the picker; the widget keeps the full picture. */
|
|
110
|
+
thumb: string;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/** The stored value that picks a built-in picture. */
|
|
114
114
|
export function presetValue(key: string): string {
|
|
115
|
-
|
|
115
|
+
return `${PRESET_PREFIX}${key}`;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/** The built-in picture a stored image value names, or undefined for an upload. */
|
|
119
119
|
export function imagePreset(value: string | null | undefined): string | undefined {
|
|
120
|
-
|
|
120
|
+
return value?.startsWith(PRESET_PREFIX) ? value.slice(PRESET_PREFIX.length) : undefined;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
export function mediaUrl(id: string | null | undefined): string | undefined {
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
if (!id || imagePreset(id) !== undefined) return undefined;
|
|
125
|
+
return useMediaStore()?.url(id);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/**
|
package/src/solid/media-tile.tsx
CHANGED
|
@@ -9,92 +9,92 @@ import { Icon } from "./icon.js";
|
|
|
9
9
|
import type { StoredMedia } from "./media-store.js";
|
|
10
10
|
|
|
11
11
|
export interface MediaTileProps {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
item: StoredMedia;
|
|
13
|
+
thumbUrl: string;
|
|
14
|
+
/** Describes what the click does here: the picker chooses, a library opens a preview. */
|
|
15
|
+
label: string;
|
|
16
|
+
broken: boolean;
|
|
17
|
+
onSelect: () => void;
|
|
18
|
+
onBroken: () => void;
|
|
19
|
+
onDelete?: () => void;
|
|
20
|
+
markUnused?: boolean;
|
|
21
|
+
selected?: boolean;
|
|
22
|
+
class?: string;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function MediaTile(props: MediaTileProps) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
26
|
+
return (
|
|
27
|
+
<div data-slot="media-tile" class={cn("relative min-w-0", props.class)}>
|
|
28
|
+
<button
|
|
29
|
+
type="button"
|
|
30
|
+
data-slot="media-tile-select"
|
|
31
|
+
data-testid="media-tile"
|
|
32
|
+
aria-label={props.label}
|
|
33
|
+
aria-pressed={props.selected}
|
|
34
|
+
onClick={() => props.onSelect()}
|
|
35
|
+
class={cn(
|
|
36
|
+
FIELD_CHROME,
|
|
37
|
+
SECTION_INNER_RADIUS,
|
|
38
|
+
"relative block aspect-square w-full overflow-hidden",
|
|
39
|
+
props.selected && "ring-primary ring-2",
|
|
40
|
+
)}
|
|
41
|
+
>
|
|
42
|
+
<Show
|
|
43
|
+
when={!props.broken}
|
|
44
|
+
fallback={
|
|
45
|
+
<span
|
|
46
|
+
data-slot="media-tile-broken"
|
|
47
|
+
data-testid="media-tile-broken"
|
|
48
|
+
class="text-muted-foreground absolute inset-0 flex items-center justify-center"
|
|
49
|
+
>
|
|
50
|
+
<Icon icon="lucide:image-off" width={20} height={20} />
|
|
51
|
+
</span>
|
|
52
|
+
}
|
|
53
|
+
>
|
|
54
|
+
<img
|
|
55
|
+
data-slot="media-tile-image"
|
|
56
|
+
src={props.thumbUrl}
|
|
57
|
+
alt={`Stored ${props.item.id}`}
|
|
58
|
+
width={props.item.width}
|
|
59
|
+
height={props.item.height}
|
|
60
|
+
loading="lazy"
|
|
61
|
+
decoding="async"
|
|
62
|
+
class="absolute inset-0 h-full w-full object-cover"
|
|
63
|
+
onError={() => props.onBroken()}
|
|
64
|
+
/>
|
|
65
|
+
</Show>
|
|
66
|
+
</button>
|
|
67
|
+
{/* Bottom-left, diagonally clear of the delete control, on the same scrim
|
|
68
|
+
* so it stays legible over a bright photo. */}
|
|
69
|
+
<Show when={props.markUnused === true && props.item.usedBy === 0}>
|
|
70
|
+
<Badge
|
|
71
|
+
data-slot="media-tile-unused"
|
|
72
|
+
data-testid="media-tile-unused"
|
|
73
|
+
tone="var(--warning)"
|
|
74
|
+
class="pointer-events-none absolute bottom-1 left-1 backdrop-blur-md"
|
|
75
|
+
>
|
|
76
|
+
Unused
|
|
77
|
+
</Badge>
|
|
78
|
+
</Show>
|
|
79
|
+
{/* Sibling, not nested: a button inside the tile button is invalid and eats the click. */}
|
|
80
|
+
<Show when={props.onDelete !== undefined}>
|
|
81
|
+
<Button
|
|
82
|
+
type="button"
|
|
83
|
+
variant="ghost"
|
|
84
|
+
size="none"
|
|
85
|
+
data-slot="media-tile-delete"
|
|
86
|
+
// after:-inset-1.5 lifts the touch target to ~44px without growing the glyph or its scrim.
|
|
87
|
+
class={cn(
|
|
88
|
+
"text-destructive hover:text-destructive absolute top-1 right-1 size-8",
|
|
89
|
+
"after:absolute after:-inset-1.5 after:content-['']",
|
|
90
|
+
SCRIM_CLASS,
|
|
91
|
+
)}
|
|
92
|
+
aria-label={`Delete ${props.item.id}`}
|
|
93
|
+
onClick={() => props.onDelete?.()}
|
|
94
|
+
>
|
|
95
|
+
<Icon icon="lucide:trash-2" width={16} height={16} />
|
|
96
|
+
</Button>
|
|
97
|
+
</Show>
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
100
|
}
|