@glasshome/ui 1.37.0 → 1.37.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/solid/index.js +3872 -3837
- package/dist/solid/popover.d.ts +3 -1
- package/package.json +1 -1
- package/src/solid/image-picker.tsx +44 -3
- package/src/solid/picker-trigger.tsx +7 -0
- package/src/solid/popover.tsx +13 -2
package/dist/solid/popover.d.ts
CHANGED
|
@@ -14,4 +14,6 @@ type PopoverContentProps = ComponentProps<typeof PopoverPrimitive.Content> & {
|
|
|
14
14
|
};
|
|
15
15
|
declare const PopoverContent: Component<PopoverContentProps>;
|
|
16
16
|
declare const PopoverAnchor: Component<ComponentProps<typeof PopoverPrimitive.Anchor>>;
|
|
17
|
-
|
|
17
|
+
/** The control, inside a PopoverAnchor, that opens its popover. */
|
|
18
|
+
declare const useAnchorTrigger: () => ((el: HTMLElement) => void) | undefined;
|
|
19
|
+
export { Popover, PopoverAnchor, PopoverContent, PopoverTrigger, useAnchorTrigger };
|
package/package.json
CHANGED
|
@@ -144,6 +144,7 @@ function ImageGallery(
|
|
|
144
144
|
const thumbUrl = (id: string) => store?.url(id, "thumb") ?? "";
|
|
145
145
|
const brokenTiles = createBrokenMedia(thumbUrl);
|
|
146
146
|
let fileInput: HTMLInputElement | undefined;
|
|
147
|
+
let uploadButton: HTMLButtonElement | undefined;
|
|
147
148
|
let panel: HTMLElement | undefined;
|
|
148
149
|
|
|
149
150
|
const [index, { refetch }] = createResource(
|
|
@@ -218,8 +219,24 @@ function ImageGallery(
|
|
|
218
219
|
// A store rejection is picker state, never an unhandled rejection escaping the tree.
|
|
219
220
|
const fail = (cause: unknown) => setError(toMediaStoreError(cause));
|
|
220
221
|
|
|
222
|
+
// A control that disables or leaves drops focus to the page, which a sealed dialog's trap moves outside, closing the gallery.
|
|
223
|
+
const holdFocus = () => panel?.focus({ preventScroll: true });
|
|
224
|
+
const focused = () => (panel?.getRootNode() as Document | ShadowRoot | undefined)?.activeElement;
|
|
225
|
+
const focusLost = () => {
|
|
226
|
+
const at = focused();
|
|
227
|
+
return !at || at === document.body;
|
|
228
|
+
};
|
|
229
|
+
let deleteFrom: Element | null | undefined;
|
|
230
|
+
let deleteConfirmed = false;
|
|
231
|
+
let confirmation: HTMLElement | undefined;
|
|
232
|
+
const focusLeaving = () => {
|
|
233
|
+
const at = focused();
|
|
234
|
+
return focusLost() || at === deleteFrom || (!!at && !!confirmation?.contains(at));
|
|
235
|
+
};
|
|
236
|
+
|
|
221
237
|
const handleUpload = async (file: File) => {
|
|
222
238
|
setError(undefined);
|
|
239
|
+
holdFocus();
|
|
223
240
|
setUploading(true);
|
|
224
241
|
try {
|
|
225
242
|
if (!store) return;
|
|
@@ -230,15 +247,18 @@ function ImageGallery(
|
|
|
230
247
|
fail(cause);
|
|
231
248
|
} finally {
|
|
232
249
|
setUploading(false);
|
|
250
|
+
if (focused() === panel) uploadButton?.focus({ preventScroll: true });
|
|
233
251
|
}
|
|
234
252
|
};
|
|
235
253
|
|
|
236
254
|
const confirmDelete = async () => {
|
|
237
255
|
const target = pendingDelete();
|
|
238
256
|
if (!target) return;
|
|
257
|
+
deleteConfirmed = true;
|
|
239
258
|
setError(undefined);
|
|
240
259
|
try {
|
|
241
260
|
await store?.remove(target.id);
|
|
261
|
+
if (focusLeaving()) holdFocus();
|
|
242
262
|
await refetch();
|
|
243
263
|
} catch (cause) {
|
|
244
264
|
fail(cause);
|
|
@@ -331,7 +351,14 @@ function ImageGallery(
|
|
|
331
351
|
variant="outline"
|
|
332
352
|
size="sm"
|
|
333
353
|
data-slot="image-picker-retry"
|
|
334
|
-
onClick={() =>
|
|
354
|
+
onClick={async () => {
|
|
355
|
+
holdFocus();
|
|
356
|
+
await Promise.resolve(refetch()).catch(() => undefined);
|
|
357
|
+
const again = panel?.querySelector<HTMLElement>(
|
|
358
|
+
'[data-slot="image-picker-retry"]',
|
|
359
|
+
);
|
|
360
|
+
if (focused() === panel) again?.focus({ preventScroll: true });
|
|
361
|
+
}}
|
|
335
362
|
>
|
|
336
363
|
Try again
|
|
337
364
|
</Button>
|
|
@@ -389,7 +416,11 @@ function ImageGallery(
|
|
|
389
416
|
onDelete={
|
|
390
417
|
store?.canRemove === false
|
|
391
418
|
? undefined
|
|
392
|
-
: () =>
|
|
419
|
+
: () => {
|
|
420
|
+
deleteFrom = focused();
|
|
421
|
+
deleteConfirmed = false;
|
|
422
|
+
setPendingDelete(tile.image);
|
|
423
|
+
}
|
|
393
424
|
}
|
|
394
425
|
/>
|
|
395
426
|
)
|
|
@@ -459,6 +490,7 @@ function ImageGallery(
|
|
|
459
490
|
type="button"
|
|
460
491
|
variant="outline"
|
|
461
492
|
size="sm"
|
|
493
|
+
ref={uploadButton}
|
|
462
494
|
data-slot="image-picker-upload"
|
|
463
495
|
disabled={uploading()}
|
|
464
496
|
onClick={() => fileInput?.click()}
|
|
@@ -476,7 +508,16 @@ function ImageGallery(
|
|
|
476
508
|
if (!next) setPendingDelete(undefined);
|
|
477
509
|
}}
|
|
478
510
|
>
|
|
479
|
-
<AlertDialogContent
|
|
511
|
+
<AlertDialogContent
|
|
512
|
+
ref={(el: HTMLElement) => (confirmation = el)}
|
|
513
|
+
onCloseAutoFocus={(event: Event) => {
|
|
514
|
+
// The confirmation has no trigger to return to; the page would get focus and the gallery would close.
|
|
515
|
+
event.preventDefault();
|
|
516
|
+
if (!deleteConfirmed && deleteFrom instanceof HTMLElement && deleteFrom.isConnected) {
|
|
517
|
+
deleteFrom.focus({ preventScroll: true });
|
|
518
|
+
} else holdFocus();
|
|
519
|
+
}}
|
|
520
|
+
>
|
|
480
521
|
<AlertDialogHeader>
|
|
481
522
|
<AlertDialogTitle>Delete image?</AlertDialogTitle>
|
|
482
523
|
<AlertDialogDescription>{deleteDescription()}</AlertDialogDescription>
|
|
@@ -2,6 +2,7 @@ import { type JSX, Show, splitProps } from "solid-js";
|
|
|
2
2
|
import { PICKER_TRIGGER } from "../lib/picker-classes.js";
|
|
3
3
|
import { cn } from "../lib/utils.js";
|
|
4
4
|
import { Icon } from "./icon.js";
|
|
5
|
+
import { useAnchorTrigger } from "./popover.js";
|
|
5
6
|
|
|
6
7
|
export interface PickerTriggerProps extends Omit<
|
|
7
8
|
JSX.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
@@ -25,11 +26,17 @@ export function PickerTrigger(props: PickerTriggerProps) {
|
|
|
25
26
|
"clearLabel",
|
|
26
27
|
"class",
|
|
27
28
|
"children",
|
|
29
|
+
"ref",
|
|
28
30
|
]);
|
|
31
|
+
const anchorTrigger = useAnchorTrigger();
|
|
29
32
|
|
|
30
33
|
return (
|
|
31
34
|
<div class="relative">
|
|
32
35
|
<button
|
|
36
|
+
ref={(el) => {
|
|
37
|
+
anchorTrigger?.(el);
|
|
38
|
+
if (typeof own.ref === "function") own.ref(el);
|
|
39
|
+
}}
|
|
33
40
|
type="button"
|
|
34
41
|
data-slot={own.slot}
|
|
35
42
|
data-expanded={own.open || undefined}
|
package/src/solid/popover.tsx
CHANGED
|
@@ -122,8 +122,19 @@ const PopoverContent: Component<PopoverContentProps> = (props) => {
|
|
|
122
122
|
);
|
|
123
123
|
};
|
|
124
124
|
|
|
125
|
+
/** Inside a PopoverAnchor: names the control that opens the popover, so focus goes back to it on close. */
|
|
126
|
+
const AnchorTriggerContext = createContext<(el: HTMLElement) => void>();
|
|
127
|
+
|
|
125
128
|
const PopoverAnchor: Component<ComponentProps<typeof PopoverPrimitive.Anchor>> = (props) => {
|
|
126
|
-
|
|
129
|
+
const popover = usePopoverContext();
|
|
130
|
+
return (
|
|
131
|
+
<AnchorTriggerContext.Provider value={popover.setTriggerRef}>
|
|
132
|
+
<PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />
|
|
133
|
+
</AnchorTriggerContext.Provider>
|
|
134
|
+
);
|
|
127
135
|
};
|
|
128
136
|
|
|
129
|
-
|
|
137
|
+
/** The control, inside a PopoverAnchor, that opens its popover. */
|
|
138
|
+
const useAnchorTrigger = () => useContext(AnchorTriggerContext);
|
|
139
|
+
|
|
140
|
+
export { Popover, PopoverAnchor, PopoverContent, PopoverTrigger, useAnchorTrigger };
|