@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
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
createEffect,
|
|
3
|
+
createMemo,
|
|
4
|
+
createResource,
|
|
5
|
+
createSignal,
|
|
6
|
+
For,
|
|
7
|
+
Match,
|
|
8
|
+
Show,
|
|
9
|
+
Switch,
|
|
10
10
|
} from "solid-js";
|
|
11
11
|
import { FIELD_CHROME } from "../lib/input-classes.js";
|
|
12
12
|
import { PICKER_LIST } from "../lib/picker-classes.js";
|
|
@@ -14,47 +14,47 @@ import { SECTION_INNER_RADIUS } from "../lib/section-tokens.js";
|
|
|
14
14
|
import { cn } from "../lib/utils.js";
|
|
15
15
|
import { Alert } from "./alert.js";
|
|
16
16
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
AlertDialog,
|
|
18
|
+
AlertDialogAction,
|
|
19
|
+
AlertDialogCancel,
|
|
20
|
+
AlertDialogContent,
|
|
21
|
+
AlertDialogDescription,
|
|
22
|
+
AlertDialogFooter,
|
|
23
|
+
AlertDialogHeader,
|
|
24
|
+
AlertDialogTitle,
|
|
25
25
|
} from "./alert-dialog.js";
|
|
26
26
|
import { Badge } from "./badge.js";
|
|
27
27
|
import { Button } from "./button.js";
|
|
28
28
|
import { formatBytes } from "./charts.js";
|
|
29
29
|
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
Empty,
|
|
31
|
+
EmptyContent,
|
|
32
|
+
EmptyDescription,
|
|
33
|
+
EmptyHeader,
|
|
34
|
+
EmptyMedia,
|
|
35
|
+
EmptyTitle,
|
|
36
36
|
} from "./empty.js";
|
|
37
37
|
import { Icon } from "./icon.js";
|
|
38
38
|
import { mediaIndexErrorCopy, mediaStoreErrorCopy, toMediaStoreError } from "./media-copy.js";
|
|
39
39
|
import {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
createBrokenMedia,
|
|
41
|
+
type ImagePreset,
|
|
42
|
+
imagePreset,
|
|
43
|
+
MEDIA_PAGE_SIZE,
|
|
44
|
+
type MediaStore,
|
|
45
|
+
type MediaStoreError,
|
|
46
|
+
presetValue,
|
|
47
|
+
type StoredMedia,
|
|
48
|
+
sortMediaForClearing,
|
|
49
|
+
useMediaStore,
|
|
50
50
|
} from "./media-store.js";
|
|
51
51
|
import { MediaTile } from "./media-tile.js";
|
|
52
52
|
import {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
Pagination,
|
|
54
|
+
PaginationContent,
|
|
55
|
+
PaginationItem,
|
|
56
|
+
PaginationNext,
|
|
57
|
+
PaginationPrevious,
|
|
58
58
|
} from "./pagination.js";
|
|
59
59
|
import { PickerTrigger } from "./picker-trigger.js";
|
|
60
60
|
import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
|
|
@@ -62,404 +62,406 @@ import { SectionMeta } from "./section-card.js";
|
|
|
62
62
|
import { Skeleton } from "./skeleton.js";
|
|
63
63
|
|
|
64
64
|
export interface ImagePickerProps {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
/** Sits on the trigger so a LabeledField's <Label for> points at a real control. */
|
|
66
|
+
id?: string;
|
|
67
|
+
value: string;
|
|
68
|
+
onChange: (id: string) => void;
|
|
69
|
+
/** Built-in pictures offered before the uploads; picking one stores `presetValue(key)`. */
|
|
70
|
+
presets?: Record<string, ImagePreset>;
|
|
71
|
+
class?: string;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export function ImagePicker(props: ImagePickerProps) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
75
|
+
const store = useMediaStore();
|
|
76
|
+
return (
|
|
77
|
+
<Show
|
|
78
|
+
when={store || props.presets}
|
|
79
|
+
fallback={
|
|
80
|
+
<div data-slot="image-picker" class={cn(props.class)}>
|
|
81
|
+
<Alert tone="info">This dashboard cannot store images.</Alert>
|
|
82
|
+
</div>
|
|
83
|
+
}
|
|
84
|
+
>
|
|
85
|
+
<ImageGallery {...props} store={store} />
|
|
86
|
+
</Show>
|
|
87
|
+
);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
type GalleryTile =
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
| { kind: "preset"; key: string; preset: ImagePreset }
|
|
92
|
+
| { kind: "media"; image: StoredMedia };
|
|
93
93
|
|
|
94
94
|
function PresetTile(props: { preset: ImagePreset; selected: boolean; onSelect: () => void }) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
95
|
+
return (
|
|
96
|
+
<div data-slot="image-picker-preset" class="relative min-w-0">
|
|
97
|
+
<button
|
|
98
|
+
type="button"
|
|
99
|
+
aria-label={`Use ${props.preset.label}`}
|
|
100
|
+
aria-pressed={props.selected}
|
|
101
|
+
onClick={() => props.onSelect()}
|
|
102
|
+
class={cn(
|
|
103
|
+
FIELD_CHROME,
|
|
104
|
+
SECTION_INNER_RADIUS,
|
|
105
|
+
"relative block aspect-square w-full overflow-hidden",
|
|
106
|
+
props.selected && "ring-primary ring-2",
|
|
107
|
+
)}
|
|
108
|
+
>
|
|
109
|
+
<img
|
|
110
|
+
src={props.preset.thumb}
|
|
111
|
+
alt={props.preset.label}
|
|
112
|
+
loading="lazy"
|
|
113
|
+
decoding="async"
|
|
114
|
+
class="absolute inset-0 h-full w-full object-cover"
|
|
115
|
+
/>
|
|
116
|
+
</button>
|
|
117
|
+
<Badge
|
|
118
|
+
tone="var(--muted-foreground)"
|
|
119
|
+
class="pointer-events-none absolute bottom-1 left-1 backdrop-blur-md"
|
|
120
|
+
>
|
|
121
|
+
Built in
|
|
122
|
+
</Badge>
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
function ImageGallery(props: ImagePickerProps & { store: MediaStore | undefined }) {
|
|
128
|
-
|
|
128
|
+
const store = props.store;
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
130
|
+
const [open, setOpen] = createSignal(false);
|
|
131
|
+
const [everOpened, setEverOpened] = createSignal(false);
|
|
132
|
+
const [error, setError] = createSignal<MediaStoreError>();
|
|
133
|
+
const [pendingDelete, setPendingDelete] = createSignal<StoredMedia>();
|
|
134
|
+
const [thumbBroken, setThumbBroken] = createSignal(false);
|
|
135
|
+
const [uploading, setUploading] = createSignal(false);
|
|
136
|
+
const [page, setPage] = createSignal(0);
|
|
137
|
+
const thumbUrl = (id: string) => store?.url(id, "thumb") ?? "";
|
|
138
|
+
const brokenTiles = createBrokenMedia(thumbUrl);
|
|
139
|
+
let fileInput: HTMLInputElement | undefined;
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
141
|
+
const [index, { refetch }] = createResource(
|
|
142
|
+
() => everOpened() && store !== undefined,
|
|
143
|
+
() => (store ? store.index() : Promise.reject(new Error("no media store"))),
|
|
144
|
+
);
|
|
145
|
+
// Reading index() on a rejected resource rethrows, which crashes the popover's
|
|
146
|
+
// portal and leaves its overlay swallowing clicks. Every read goes through this.
|
|
147
|
+
const indexError = createMemo(() =>
|
|
148
|
+
index.error === undefined ? undefined : toMediaStoreError(index.error),
|
|
149
|
+
);
|
|
150
|
+
const loaded = () => (index.error === undefined ? index() : undefined);
|
|
151
|
+
const sorted = createMemo(() => sortMediaForClearing(loaded()?.media ?? []));
|
|
152
|
+
// Built-in pictures lead the grid; the household's uploads follow them.
|
|
153
|
+
const tiles = createMemo<GalleryTile[]>(() => [
|
|
154
|
+
...Object.entries(props.presets ?? {}).map(([key, preset]): GalleryTile => ({
|
|
155
|
+
kind: "preset",
|
|
156
|
+
key,
|
|
157
|
+
preset,
|
|
158
|
+
})),
|
|
159
|
+
...sorted().map((image): GalleryTile => ({ kind: "media", image })),
|
|
160
|
+
]);
|
|
161
|
+
const pageCount = createMemo(() => Math.max(1, Math.ceil(tiles().length / MEDIA_PAGE_SIZE)));
|
|
162
|
+
const current = createMemo(() => Math.min(page(), pageCount() - 1));
|
|
163
|
+
const pageTiles = createMemo(() =>
|
|
164
|
+
tiles().slice(current() * MEDIA_PAGE_SIZE, current() * MEDIA_PAGE_SIZE + MEDIA_PAGE_SIZE),
|
|
165
|
+
);
|
|
166
|
+
const deleteDescription = createMemo(() => {
|
|
167
|
+
const used = pendingDelete()?.usedBy ?? 0;
|
|
168
|
+
return used === 0
|
|
169
|
+
? "This image isn't used by any widget."
|
|
170
|
+
: `This image is used in ${used} widget${used === 1 ? "" : "s"}. Deleting it will leave those widgets without an image.`;
|
|
171
|
+
});
|
|
170
172
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
const chosenPreset = () => {
|
|
174
|
+
const key = imagePreset(props.value);
|
|
175
|
+
return key === undefined ? undefined : props.presets?.[key];
|
|
176
|
+
};
|
|
175
177
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
178
|
+
const pick = (value: string) => {
|
|
179
|
+
props.onChange(props.value === value ? "" : value);
|
|
180
|
+
setThumbBroken(false);
|
|
181
|
+
setOpen(false);
|
|
182
|
+
};
|
|
181
183
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
const clearImage = () => {
|
|
185
|
+
props.onChange("");
|
|
186
|
+
setThumbBroken(false);
|
|
187
|
+
};
|
|
186
188
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
const openGallery = (next: boolean) => {
|
|
190
|
+
if (next) setEverOpened(true);
|
|
191
|
+
setOpen(next);
|
|
192
|
+
};
|
|
191
193
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
194
|
+
// A gallery reopened after a failed upload starts clean; a stale banner reads as a fresh failure.
|
|
195
|
+
createEffect(() => {
|
|
196
|
+
if (open()) {
|
|
197
|
+
setError(undefined);
|
|
198
|
+
setPage(0);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
199
201
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
+
const step = (delta: number) =>
|
|
203
|
+
setPage(Math.min(Math.max(current() + delta, 0), pageCount() - 1));
|
|
202
204
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
+
// A store rejection is picker state, never an unhandled rejection escaping the tree.
|
|
206
|
+
const fail = (cause: unknown) => setError(toMediaStoreError(cause));
|
|
205
207
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
208
|
+
const handleUpload = async (file: File) => {
|
|
209
|
+
setError(undefined);
|
|
210
|
+
setUploading(true);
|
|
211
|
+
try {
|
|
212
|
+
if (!store) return;
|
|
213
|
+
const uploaded = await store.upload(file);
|
|
214
|
+
await refetch();
|
|
215
|
+
props.onChange(uploaded.id);
|
|
216
|
+
} catch (cause) {
|
|
217
|
+
fail(cause);
|
|
218
|
+
} finally {
|
|
219
|
+
setUploading(false);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
220
222
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
223
|
+
const confirmDelete = async () => {
|
|
224
|
+
const target = pendingDelete();
|
|
225
|
+
if (!target) return;
|
|
226
|
+
setError(undefined);
|
|
227
|
+
try {
|
|
228
|
+
await store?.remove(target.id);
|
|
229
|
+
await refetch();
|
|
230
|
+
} catch (cause) {
|
|
231
|
+
fail(cause);
|
|
232
|
+
} finally {
|
|
233
|
+
setPendingDelete(undefined);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
234
236
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
237
|
+
return (
|
|
238
|
+
<div data-slot="image-picker" class={cn(props.class)}>
|
|
239
|
+
<Popover surface="field" open={open()} onOpenChange={openGallery} modal>
|
|
240
|
+
<PopoverAnchor as="div">
|
|
241
|
+
<PickerTrigger
|
|
242
|
+
id={props.id}
|
|
243
|
+
slot="image-picker-trigger"
|
|
244
|
+
open={open()}
|
|
245
|
+
onToggle={() => openGallery(!open())}
|
|
246
|
+
onClear={props.value ? clearImage : undefined}
|
|
247
|
+
clearLabel="Clear image"
|
|
248
|
+
>
|
|
249
|
+
<Show
|
|
250
|
+
when={!thumbBroken() && props.value && (chosenPreset() ?? store)}
|
|
251
|
+
fallback={
|
|
252
|
+
<>
|
|
253
|
+
<Icon
|
|
254
|
+
icon={thumbBroken() ? "lucide:image-off" : "lucide:image"}
|
|
255
|
+
width={18}
|
|
256
|
+
height={18}
|
|
257
|
+
class="text-muted-foreground shrink-0"
|
|
258
|
+
/>
|
|
259
|
+
<span class="text-muted-foreground flex-1 truncate text-left">
|
|
260
|
+
{thumbBroken() ? "Image unavailable" : "Choose image"}
|
|
261
|
+
</span>
|
|
262
|
+
</>
|
|
263
|
+
}
|
|
264
|
+
>
|
|
265
|
+
<img
|
|
266
|
+
src={chosenPreset()?.thumb ?? store?.url(props.value)}
|
|
267
|
+
alt=""
|
|
268
|
+
width={24}
|
|
269
|
+
height={24}
|
|
270
|
+
decoding="async"
|
|
271
|
+
class="size-6 shrink-0 rounded-sm object-cover"
|
|
272
|
+
onError={() => setThumbBroken(true)}
|
|
273
|
+
/>
|
|
274
|
+
<span class="flex-1 truncate text-left">
|
|
275
|
+
{chosenPreset()?.label ?? "Image selected"}
|
|
276
|
+
</span>
|
|
277
|
+
</Show>
|
|
278
|
+
</PickerTrigger>
|
|
279
|
+
</PopoverAnchor>
|
|
280
|
+
<PopoverContent class="min-w-72" onInteractOutside={() => setOpen(false)}>
|
|
281
|
+
{/* The panel owns no padding: the gallery body owns its own inset. */}
|
|
282
|
+
<div data-slot="image-picker-body" class="flex flex-col gap-3 p-3">
|
|
283
|
+
<Show when={error()}>
|
|
284
|
+
{(err) => (
|
|
285
|
+
<Alert tone="destructive" role="alert">
|
|
286
|
+
{mediaStoreErrorCopy(err())}
|
|
287
|
+
</Alert>
|
|
288
|
+
)}
|
|
289
|
+
</Show>
|
|
290
|
+
<Show when={indexError()}>
|
|
291
|
+
{(failure) => (
|
|
292
|
+
// role="status": the gallery is explaining itself, not raising an alarm.
|
|
293
|
+
<Empty role="status">
|
|
294
|
+
<EmptyHeader>
|
|
295
|
+
<EmptyMedia variant="icon">
|
|
296
|
+
<Icon icon="lucide:image-off" width={24} height={24} />
|
|
297
|
+
</EmptyMedia>
|
|
298
|
+
<EmptyTitle>Images unavailable</EmptyTitle>
|
|
299
|
+
<EmptyDescription>{mediaIndexErrorCopy(failure())}</EmptyDescription>
|
|
300
|
+
</EmptyHeader>
|
|
301
|
+
<EmptyContent>
|
|
302
|
+
<Button
|
|
303
|
+
type="button"
|
|
304
|
+
variant="outline"
|
|
305
|
+
size="sm"
|
|
306
|
+
data-slot="image-picker-retry"
|
|
307
|
+
onClick={() => void refetch()}
|
|
308
|
+
>
|
|
309
|
+
Try again
|
|
310
|
+
</Button>
|
|
311
|
+
</EmptyContent>
|
|
312
|
+
</Empty>
|
|
313
|
+
)}
|
|
314
|
+
</Show>
|
|
315
|
+
<Show
|
|
316
|
+
when={tiles().length > 0}
|
|
317
|
+
fallback={
|
|
318
|
+
<Switch>
|
|
319
|
+
<Match when={store && !loaded() && !indexError()}>
|
|
320
|
+
<div data-slot="image-picker-loading" class="grid grid-cols-3 gap-2">
|
|
321
|
+
<For each={[0, 1, 2, 3, 4, 5]}>
|
|
322
|
+
{() => <Skeleton class="aspect-square" />}
|
|
323
|
+
</For>
|
|
324
|
+
</div>
|
|
325
|
+
</Match>
|
|
326
|
+
<Match when={loaded()}>
|
|
327
|
+
<Empty>
|
|
328
|
+
<EmptyHeader>
|
|
329
|
+
<EmptyMedia variant="icon">
|
|
330
|
+
<Icon icon="lucide:image" width={24} height={24} />
|
|
331
|
+
</EmptyMedia>
|
|
332
|
+
<EmptyTitle>No images yet</EmptyTitle>
|
|
333
|
+
<EmptyDescription>Upload one to use it here.</EmptyDescription>
|
|
334
|
+
</EmptyHeader>
|
|
335
|
+
</Empty>
|
|
336
|
+
</Match>
|
|
337
|
+
</Switch>
|
|
338
|
+
}
|
|
339
|
+
>
|
|
340
|
+
<div
|
|
341
|
+
data-slot="image-picker-gallery"
|
|
342
|
+
class={cn("grid grid-cols-3 gap-2", PICKER_LIST, "overflow-x-hidden")}
|
|
343
|
+
>
|
|
344
|
+
<For each={pageTiles()}>
|
|
345
|
+
{(tile) =>
|
|
346
|
+
tile.kind === "preset" ? (
|
|
347
|
+
<PresetTile
|
|
348
|
+
preset={tile.preset}
|
|
349
|
+
selected={props.value === presetValue(tile.key)}
|
|
350
|
+
onSelect={() => pick(presetValue(tile.key))}
|
|
351
|
+
/>
|
|
352
|
+
) : (
|
|
353
|
+
<MediaTile
|
|
354
|
+
item={tile.image}
|
|
355
|
+
thumbUrl={thumbUrl(tile.image.id)}
|
|
356
|
+
label={`Use ${tile.image.id}`}
|
|
357
|
+
broken={brokenTiles.isBroken(tile.image)}
|
|
358
|
+
markUnused
|
|
359
|
+
selected={props.value === tile.image.id}
|
|
360
|
+
onSelect={() => pick(tile.image.id)}
|
|
361
|
+
onBroken={() => brokenTiles.markBroken(tile.image)}
|
|
362
|
+
onDelete={() => setPendingDelete(tile.image)}
|
|
363
|
+
/>
|
|
364
|
+
)
|
|
365
|
+
}
|
|
366
|
+
</For>
|
|
367
|
+
</div>
|
|
368
|
+
<Show when={pageCount() > 1}>
|
|
369
|
+
<Pagination>
|
|
370
|
+
<PaginationContent class="w-full justify-between">
|
|
371
|
+
<PaginationItem>
|
|
372
|
+
<PaginationPrevious
|
|
373
|
+
href="#"
|
|
374
|
+
aria-disabled={current() === 0}
|
|
375
|
+
class={current() === 0 ? "pointer-events-none opacity-50" : undefined}
|
|
376
|
+
onClick={(event) => {
|
|
377
|
+
event.preventDefault();
|
|
378
|
+
step(-1);
|
|
379
|
+
}}
|
|
380
|
+
/>
|
|
381
|
+
</PaginationItem>
|
|
382
|
+
<PaginationItem data-testid="image-picker-page-label">
|
|
383
|
+
<SectionMeta>
|
|
384
|
+
Page {current() + 1} of {pageCount()}
|
|
385
|
+
</SectionMeta>
|
|
386
|
+
</PaginationItem>
|
|
387
|
+
<PaginationItem>
|
|
388
|
+
<PaginationNext
|
|
389
|
+
href="#"
|
|
390
|
+
aria-disabled={current() === pageCount() - 1}
|
|
391
|
+
class={
|
|
392
|
+
current() === pageCount() - 1
|
|
393
|
+
? "pointer-events-none opacity-50"
|
|
394
|
+
: undefined
|
|
395
|
+
}
|
|
396
|
+
onClick={(event) => {
|
|
397
|
+
event.preventDefault();
|
|
398
|
+
step(1);
|
|
399
|
+
}}
|
|
400
|
+
/>
|
|
401
|
+
</PaginationItem>
|
|
402
|
+
</PaginationContent>
|
|
403
|
+
</Pagination>
|
|
404
|
+
</Show>
|
|
405
|
+
</Show>
|
|
406
|
+
<Show when={loaded()?.usage}>
|
|
407
|
+
{(u) => (
|
|
408
|
+
<SectionMeta>
|
|
409
|
+
{formatBytes(u().bytes)} of {formatBytes(u().limitBytes)} · {u().files} of{" "}
|
|
410
|
+
{u().limitFiles} images
|
|
411
|
+
</SectionMeta>
|
|
412
|
+
)}
|
|
413
|
+
</Show>
|
|
414
|
+
<Show when={store}>
|
|
415
|
+
<input
|
|
416
|
+
ref={fileInput}
|
|
417
|
+
type="file"
|
|
418
|
+
accept="image/*"
|
|
419
|
+
data-testid="image-upload-input"
|
|
420
|
+
class="hidden"
|
|
421
|
+
onChange={(e) => {
|
|
422
|
+
const file = e.currentTarget.files?.[0];
|
|
423
|
+
e.currentTarget.value = "";
|
|
424
|
+
if (file) void handleUpload(file);
|
|
425
|
+
}}
|
|
426
|
+
/>
|
|
427
|
+
<Button
|
|
428
|
+
type="button"
|
|
429
|
+
variant="outline"
|
|
430
|
+
size="sm"
|
|
431
|
+
data-slot="image-picker-upload"
|
|
432
|
+
disabled={uploading()}
|
|
433
|
+
onClick={() => fileInput?.click()}
|
|
434
|
+
>
|
|
435
|
+
<Icon icon="lucide:upload" width={14} height={14} />
|
|
436
|
+
{uploading() ? "Uploading..." : "Upload"}
|
|
437
|
+
</Button>
|
|
438
|
+
</Show>
|
|
439
|
+
</div>
|
|
440
|
+
</PopoverContent>
|
|
441
|
+
</Popover>
|
|
442
|
+
<AlertDialog
|
|
443
|
+
open={pendingDelete() !== undefined}
|
|
444
|
+
onOpenChange={(next) => {
|
|
445
|
+
if (!next) setPendingDelete(undefined);
|
|
446
|
+
}}
|
|
447
|
+
>
|
|
448
|
+
<AlertDialogContent>
|
|
449
|
+
<AlertDialogHeader>
|
|
450
|
+
<AlertDialogTitle>Delete image?</AlertDialogTitle>
|
|
451
|
+
<AlertDialogDescription>{deleteDescription()}</AlertDialogDescription>
|
|
452
|
+
</AlertDialogHeader>
|
|
453
|
+
<AlertDialogFooter>
|
|
454
|
+
<AlertDialogCancel aria-label="Cancel">Cancel</AlertDialogCancel>
|
|
455
|
+
<AlertDialogAction
|
|
456
|
+
variant="destructive"
|
|
457
|
+
aria-label="Delete"
|
|
458
|
+
onClick={() => void confirmDelete()}
|
|
459
|
+
>
|
|
460
|
+
Delete
|
|
461
|
+
</AlertDialogAction>
|
|
462
|
+
</AlertDialogFooter>
|
|
463
|
+
</AlertDialogContent>
|
|
464
|
+
</AlertDialog>
|
|
465
|
+
</div>
|
|
466
|
+
);
|
|
465
467
|
}
|