@glasshome/ui 1.43.0 → 1.44.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.
- package/SPEC.md +8 -5
- package/dist/index.js +2 -2
- package/dist/lib/behavior/anchored.d.ts +7 -8
- package/dist/lib/behavior/focus-scope.d.ts +4 -2
- package/dist/lib/behavior/menu.d.ts +3 -0
- package/dist/lib/motion-classes.d.ts +1 -0
- package/dist/solid/data-table.d.ts +4 -2
- package/dist/solid/index.js +3115 -3123
- package/dist/{utils-3Codx-NZ.js → utils-BbIeGt7o.js} +524 -500
- package/package.json +1 -1
- package/src/lib/behavior/anchored.ts +17 -3
- package/src/lib/behavior/collection.ts +9 -18
- package/src/lib/behavior/focus-scope.ts +51 -10
- package/src/lib/behavior/menu.ts +20 -28
- package/src/lib/behavior/modal-root.tsx +2 -2
- package/src/lib/clipboard.ts +2 -2
- package/src/lib/motion-classes.ts +1 -2
- package/src/solid/area-picker.tsx +1 -2
- package/src/solid/bottom-sheet/arbitration.ts +4 -11
- package/src/solid/bottom-sheet/bottom-sheet.tsx +3 -4
- package/src/solid/bottom-sheet/drag-controller.ts +7 -20
- package/src/solid/data-table.tsx +48 -22
- package/src/solid/dialog-parts.tsx +30 -8
- package/src/solid/dock.tsx +41 -41
- package/src/solid/entity-selector.tsx +0 -1
- package/src/solid/icon-picker.tsx +1 -2
- package/src/solid/image-picker.tsx +2 -2
- package/src/solid/menu-parts.tsx +1 -20
- package/src/solid/option-card.tsx +1 -3
- package/src/solid/popover.tsx +10 -12
- package/src/solid/select.tsx +4 -15
- package/src/solid/selection.tsx +28 -13
- package/src/solid/sliding-indicator.tsx +3 -15
- package/src/solid/toggle-group.tsx +5 -2
- package/src/styles/globals.css +0 -43
- package/src/styles/theme.css +11 -2
package/src/solid/data-table.tsx
CHANGED
|
@@ -60,10 +60,13 @@ export function TableFilterSelect(props: {
|
|
|
60
60
|
options: readonly string[];
|
|
61
61
|
value: string;
|
|
62
62
|
onChange: (value: string) => void;
|
|
63
|
-
label: (value: string) =>
|
|
63
|
+
label: (value: string) => JSX.Element;
|
|
64
64
|
ariaLabel: string;
|
|
65
|
+
/** Leading icon, `prefix:name`; defaults to the filter funnel. */
|
|
66
|
+
icon?: string;
|
|
65
67
|
class?: string;
|
|
66
68
|
}) {
|
|
69
|
+
const icon = createMemo(() => props.icon ?? "lucide:funnel");
|
|
67
70
|
return (
|
|
68
71
|
<Select<string>
|
|
69
72
|
options={[...props.options]}
|
|
@@ -76,12 +79,11 @@ export function TableFilterSelect(props: {
|
|
|
76
79
|
)}
|
|
77
80
|
>
|
|
78
81
|
<SelectTrigger
|
|
79
|
-
data-slot="table-filter-select"
|
|
80
82
|
class={cn("h-9 w-auto gap-1.5 text-xs", props.class)}
|
|
81
83
|
aria-label={props.ariaLabel}
|
|
82
84
|
>
|
|
83
85
|
<Icon
|
|
84
|
-
icon=
|
|
86
|
+
icon={icon()}
|
|
85
87
|
width={14}
|
|
86
88
|
height={14}
|
|
87
89
|
class="text-muted-foreground size-3.5 shrink-0"
|
|
@@ -214,6 +216,7 @@ export function TableSortHeader(props: {
|
|
|
214
216
|
align?: "start" | "end";
|
|
215
217
|
class?: string;
|
|
216
218
|
}) {
|
|
219
|
+
const label = createMemo(() => props.label);
|
|
217
220
|
return (
|
|
218
221
|
<Button
|
|
219
222
|
type="button"
|
|
@@ -226,9 +229,9 @@ export function TableSortHeader(props: {
|
|
|
226
229
|
props.align === "end" ? "justify-end" : "justify-start",
|
|
227
230
|
props.class,
|
|
228
231
|
)}
|
|
229
|
-
aria-label={`Sort by ${
|
|
232
|
+
aria-label={`Sort by ${label()}`}
|
|
230
233
|
>
|
|
231
|
-
{
|
|
234
|
+
{label()}
|
|
232
235
|
<Show
|
|
233
236
|
when={props.active}
|
|
234
237
|
fallback={
|
|
@@ -289,7 +292,27 @@ export function TableError(props: { message: JSX.Element; onRetry: () => void })
|
|
|
289
292
|
);
|
|
290
293
|
}
|
|
291
294
|
|
|
292
|
-
|
|
295
|
+
const nearEnd = new Map<Element, () => void>();
|
|
296
|
+
let endWatcher: IntersectionObserver | undefined;
|
|
297
|
+
|
|
298
|
+
// One observer serves every table's end, so a page of tables pays for one.
|
|
299
|
+
function watchNearEnd(target: Element, onNear: () => void): () => void {
|
|
300
|
+
endWatcher ??= new IntersectionObserver(
|
|
301
|
+
(entries) => {
|
|
302
|
+
for (const entry of entries) if (entry.isIntersecting) nearEnd.get(entry.target)?.();
|
|
303
|
+
},
|
|
304
|
+
{ rootMargin: "400px" },
|
|
305
|
+
);
|
|
306
|
+
const watcher = endWatcher;
|
|
307
|
+
nearEnd.set(target, onNear);
|
|
308
|
+
watcher.observe(target);
|
|
309
|
+
return () => {
|
|
310
|
+
nearEnd.delete(target);
|
|
311
|
+
watcher.unobserve(target);
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** The end of a long table: once the page scrolls, asks for the next page as it nears the viewport; or on press. */
|
|
293
316
|
export function TableLoadMore(props: {
|
|
294
317
|
hasMore: boolean;
|
|
295
318
|
loading?: boolean;
|
|
@@ -299,26 +322,29 @@ export function TableLoadMore(props: {
|
|
|
299
322
|
}) {
|
|
300
323
|
let sentinel: HTMLDivElement | undefined;
|
|
301
324
|
onMount(() => {
|
|
302
|
-
if (!sentinel || typeof IntersectionObserver === "undefined") return;
|
|
303
325
|
const target = sentinel;
|
|
326
|
+
if (!target || typeof IntersectionObserver === "undefined") return;
|
|
304
327
|
let frame = 0;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
)
|
|
318
|
-
|
|
328
|
+
let unwatch: (() => void) | undefined;
|
|
329
|
+
const onNear = () => {
|
|
330
|
+
if (!props.hasMore || props.loading) return;
|
|
331
|
+
props.onLoadMore();
|
|
332
|
+
// A page too short to push the sentinel out of view never fires again on its own.
|
|
333
|
+
cancelAnimationFrame(frame);
|
|
334
|
+
frame = requestAnimationFrame(() => {
|
|
335
|
+
unwatch?.();
|
|
336
|
+
unwatch = watchNearEnd(target, onNear);
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
// A table nobody scrolls never pays for an observer.
|
|
340
|
+
const arm = () => {
|
|
341
|
+
unwatch ??= watchNearEnd(target, onNear);
|
|
342
|
+
};
|
|
343
|
+
window.addEventListener("scroll", arm, { capture: true, passive: true, once: true });
|
|
319
344
|
onCleanup(() => {
|
|
345
|
+
window.removeEventListener("scroll", arm, { capture: true });
|
|
320
346
|
cancelAnimationFrame(frame);
|
|
321
|
-
|
|
347
|
+
unwatch?.();
|
|
322
348
|
});
|
|
323
349
|
});
|
|
324
350
|
return (
|
|
@@ -183,10 +183,13 @@ const MODAL_HEADER_ACTION = "flex shrink-0 items-center gap-2";
|
|
|
183
183
|
* - The reserved scrollbar lives inside the right inset, so the content column
|
|
184
184
|
* ends where the Header's and Footer's do. */
|
|
185
185
|
const MODAL_BODY =
|
|
186
|
-
"gh-scroll
|
|
186
|
+
"gh-scroll relative flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain [touch-action:pan-y_pinch-zoom] [scrollbar-gutter:stable] pl-6 pr-[calc(var(--spacing)*6-var(--scrollbar-gutter,var(--scrollbar-w)))] pt-6 pb-6 [[data-slot$='-header']~&]:pt-3 [&:has(~[data-slot$='-footer'])]:pb-3 in-data-[slot=bottom-sheet-content]:pl-4 in-data-[slot=bottom-sheet-content]:pr-[calc(var(--spacing)*4-var(--scrollbar-gutter,var(--scrollbar-w)))] [[data-slot=bottom-sheet-handle]+&]:pt-1";
|
|
187
|
+
|
|
188
|
+
// Out of flow, so content keeps its gap and its first child; it marks where the scroll starts.
|
|
189
|
+
const MODAL_BODY_TOP = "pointer-events-none absolute inset-x-0 top-0 h-px";
|
|
187
190
|
|
|
188
191
|
const MODAL_FOOTER =
|
|
189
|
-
"
|
|
192
|
+
"flex shrink-0 flex-col-reverse gap-2 px-6 pt-3 pb-6 sm:flex-row sm:justify-end in-data-[slot=bottom-sheet-content]:px-4";
|
|
190
193
|
|
|
191
194
|
export const MODAL_TITLE = "font-semibold text-foreground text-lg leading-none tracking-tight";
|
|
192
195
|
export const MODAL_DESCRIPTION = "text-muted-foreground text-sm";
|
|
@@ -238,16 +241,33 @@ export function createModalParts(slot: string): ModalParts {
|
|
|
238
241
|
);
|
|
239
242
|
};
|
|
240
243
|
|
|
241
|
-
/* data-sheet-scroll is the bottom sheet's drag arbitration marker: a Body
|
|
242
|
-
* inside a sheet must yield the gesture to its own scroll, whichever family
|
|
243
|
-
* rendered it. */
|
|
244
244
|
const Body: Component<ModalBodyProps> = (props) => {
|
|
245
|
-
const [local, rest] = splitProps(props, ["class", "as", "ref"]);
|
|
245
|
+
const [local, rest] = splitProps(props, ["class", "as", "ref", "children"]);
|
|
246
246
|
let el: HTMLElement | undefined;
|
|
247
|
+
let top: HTMLSpanElement | undefined;
|
|
247
248
|
// Overlay scrollbars reserve no gutter, so the right inset subtracts what the platform actually reserved.
|
|
248
249
|
onMount(() => {
|
|
249
250
|
if (el) el.style.setProperty("--scrollbar-gutter", `${el.offsetWidth - el.clientWidth}px`);
|
|
250
251
|
});
|
|
252
|
+
// data-scrolled comes from an observer, since a sealed widget cannot read scrollTop; made on the first scroll, as an observer costs a call to the page.
|
|
253
|
+
let observer: IntersectionObserver | undefined;
|
|
254
|
+
const watchTop = () => {
|
|
255
|
+
const box = el;
|
|
256
|
+
if (!box || !top || observer) return;
|
|
257
|
+
observer = new IntersectionObserver(
|
|
258
|
+
(entries) => {
|
|
259
|
+
const entry = entries[entries.length - 1];
|
|
260
|
+
if (entry) box.toggleAttribute("data-scrolled", entry.intersectionRatio < 0.99);
|
|
261
|
+
},
|
|
262
|
+
{ root: box, threshold: [0.99] },
|
|
263
|
+
);
|
|
264
|
+
observer.observe(top);
|
|
265
|
+
};
|
|
266
|
+
onMount(() => el?.addEventListener("scroll", watchTop, { once: true, passive: true }));
|
|
267
|
+
onCleanup(() => {
|
|
268
|
+
el?.removeEventListener("scroll", watchTop);
|
|
269
|
+
observer?.disconnect();
|
|
270
|
+
});
|
|
251
271
|
return (
|
|
252
272
|
<Polymorphic
|
|
253
273
|
defaultAs="div"
|
|
@@ -257,10 +277,12 @@ export function createModalParts(slot: string): ModalParts {
|
|
|
257
277
|
if (typeof local.ref === "function") local.ref(node as HTMLDivElement);
|
|
258
278
|
}}
|
|
259
279
|
data-slot={`${slot}-body`}
|
|
260
|
-
data-sheet-scroll=""
|
|
261
280
|
class={cn(MODAL_BODY, local.class)}
|
|
262
281
|
{...rest}
|
|
263
|
-
|
|
282
|
+
>
|
|
283
|
+
<span ref={top} aria-hidden="true" class={MODAL_BODY_TOP} />
|
|
284
|
+
{local.children}
|
|
285
|
+
</Polymorphic>
|
|
264
286
|
);
|
|
265
287
|
};
|
|
266
288
|
|
package/src/solid/dock.tsx
CHANGED
|
@@ -246,33 +246,31 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
246
246
|
const scrollPos = (el: HTMLElement) => (vertical() ? el.scrollTop : el.scrollLeft);
|
|
247
247
|
const edgeStart = (rect: DOMRect) => (vertical() ? rect.top : rect.left);
|
|
248
248
|
|
|
249
|
-
const gapSize = () => {
|
|
250
|
-
if (!containerRef) return 0;
|
|
251
|
-
const style = getComputedStyle(containerRef);
|
|
252
|
-
return Number.parseFloat(vertical() ? style.rowGap : style.columnGap) || 0;
|
|
253
|
-
};
|
|
254
249
|
const itemSize = () => {
|
|
255
250
|
const rect = containerRef?.querySelector('[data-slot="dock-item"]')?.getBoundingClientRect();
|
|
256
251
|
return (vertical() ? rect?.height : rect?.width) ?? 0;
|
|
257
252
|
};
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
? [style.paddingTop, style.paddingBottom]
|
|
263
|
-
: [style.paddingLeft, style.paddingRight];
|
|
264
|
-
return (Number.parseFloat(a) || 0) + (Number.parseFloat(b) || 0);
|
|
253
|
+
// Slots sit evenly, so the strip's length gives the gap without a style read.
|
|
254
|
+
const gapSize = (scroll: number, item: number) => {
|
|
255
|
+
const slots = local.items.length + (local.editing && local.onAdd ? 1 : 0);
|
|
256
|
+
return slots > 1 ? Math.max(0, (scroll - slots * item) / (slots - 1)) : 0;
|
|
265
257
|
};
|
|
266
258
|
|
|
259
|
+
let room: ResizeObserverSize | undefined;
|
|
260
|
+
let surfaceSize: { content: ResizeObserverSize; border: ResizeObserverSize } | undefined;
|
|
261
|
+
let companionSize: ResizeObserverSize | undefined;
|
|
262
|
+
const along = (size: ResizeObserverSize | undefined) =>
|
|
263
|
+
(vertical() ? size?.blockSize : size?.inlineSize) ?? 0;
|
|
264
|
+
|
|
267
265
|
// The room the app gave the dock. Never the surface: it shrink-wraps this strip,
|
|
268
266
|
// so measuring it asks the strip how big the strip is.
|
|
269
267
|
const availableSpan = () => {
|
|
270
|
-
|
|
271
|
-
|
|
268
|
+
if (!room || !surfaceSize) return 0;
|
|
269
|
+
const chrome = along(surfaceSize.border) - along(surfaceSize.content);
|
|
272
270
|
const lead = leadRef ? (vertical() ? leadRef.offsetHeight : leadRef.offsetWidth) : 0;
|
|
273
271
|
// A side dock's companion stacks along the edge, so the strip gives up its height.
|
|
274
|
-
const companion = vertical() && local.companionOpen ? (
|
|
275
|
-
return
|
|
272
|
+
const companion = vertical() && local.companionOpen ? along(companionSize) : 0;
|
|
273
|
+
return along(room) - chrome - lead - companion;
|
|
276
274
|
};
|
|
277
275
|
|
|
278
276
|
const checkOverflow = () => {
|
|
@@ -281,9 +279,11 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
281
279
|
const other = vertical() ? "width" : "height";
|
|
282
280
|
containerRef.style.removeProperty(other);
|
|
283
281
|
const available = availableSpan();
|
|
284
|
-
const
|
|
282
|
+
const scroll = scrollSize(containerRef);
|
|
283
|
+
const overflowing = available > 0 && scroll > available + 1;
|
|
285
284
|
if (overflowing) {
|
|
286
|
-
const
|
|
285
|
+
const item = itemSize();
|
|
286
|
+
const trimmed = stripWidth(available, item, gapSize(scroll, item));
|
|
287
287
|
if (trimmed > 0) containerRef.style[side] = `${trimmed}px`;
|
|
288
288
|
} else if (containerRef.style[side]) {
|
|
289
289
|
containerRef.style[side] = "";
|
|
@@ -298,9 +298,9 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
298
298
|
const goToPage = (next: number) => {
|
|
299
299
|
if (!containerRef) return;
|
|
300
300
|
const to = pageOffset(next, viewportSpan(), scrollSize(containerRef));
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
301
|
+
// The strip's scroll-smooth class carries the motion.
|
|
302
|
+
if (vertical()) containerRef.scrollTop = to;
|
|
303
|
+
else containerRef.scrollLeft = to;
|
|
304
304
|
};
|
|
305
305
|
|
|
306
306
|
const turnToItem = (index: number) => {
|
|
@@ -360,31 +360,31 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
360
360
|
),
|
|
361
361
|
);
|
|
362
362
|
|
|
363
|
-
// Measured in the next frame's callbacks, which run before it paints: the first
|
|
364
|
-
// dock anyone sees already has its pages, so the dot row never shifts it later.
|
|
365
|
-
onMount(() => {
|
|
366
|
-
let resizeFrame = 0;
|
|
367
|
-
const onResize = () => {
|
|
368
|
-
cancelAnimationFrame(resizeFrame);
|
|
369
|
-
resizeFrame = requestAnimationFrame(checkOverflow);
|
|
370
|
-
};
|
|
371
|
-
window.addEventListener("resize", onResize);
|
|
372
|
-
onCleanup(() => {
|
|
373
|
-
cancelAnimationFrame(resizeFrame);
|
|
374
|
-
window.removeEventListener("resize", onResize);
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
// The companion's own content can change height while open, under a side dock that is the strip's room.
|
|
379
363
|
onMount(() => {
|
|
380
|
-
|
|
364
|
+
const box = containerRef.closest('[data-slot="dock"]');
|
|
365
|
+
if (!box || !surfaceRef) return;
|
|
366
|
+
const surface = surfaceRef;
|
|
381
367
|
let frame = 0;
|
|
382
|
-
const
|
|
383
|
-
|
|
368
|
+
const measured = () =>
|
|
369
|
+
`${along(room)} ${along(surfaceSize?.border) - along(surfaceSize?.content)} ${along(companionSize)}`;
|
|
370
|
+
const observer = new ResizeObserver((entries) => {
|
|
371
|
+
const before = measured();
|
|
372
|
+
for (const entry of entries) {
|
|
373
|
+
const [content] = entry.contentBoxSize;
|
|
374
|
+
const [border] = entry.borderBoxSize;
|
|
375
|
+
if (!content || !border) continue;
|
|
376
|
+
if (entry.target === box) room = content;
|
|
377
|
+
else if (entry.target === surface) surfaceSize = { content, border };
|
|
378
|
+
else companionSize = border;
|
|
379
|
+
}
|
|
380
|
+
if (measured() === before) return;
|
|
381
|
+
// Paging resizes what other observers on the page watch; inside this callback that is a resize loop.
|
|
384
382
|
cancelAnimationFrame(frame);
|
|
385
383
|
frame = requestAnimationFrame(checkOverflow);
|
|
386
384
|
});
|
|
387
|
-
observer.observe(
|
|
385
|
+
observer.observe(box);
|
|
386
|
+
observer.observe(surface, { box: "border-box" });
|
|
387
|
+
if (companionRef) observer.observe(companionRef, { box: "border-box" });
|
|
388
388
|
onCleanup(() => {
|
|
389
389
|
cancelAnimationFrame(frame);
|
|
390
390
|
observer.disconnect();
|
|
@@ -473,7 +473,6 @@ export function EntitySelector(props: EntitySelectorProps) {
|
|
|
473
473
|
role="listbox"
|
|
474
474
|
aria-multiselectable={!isSingle()}
|
|
475
475
|
aria-label={`${props.domain} entities`}
|
|
476
|
-
data-sheet-scroll=""
|
|
477
476
|
class={cn(
|
|
478
477
|
"min-h-0 flex-1 touch-pan-y overscroll-contain px-1 py-1",
|
|
479
478
|
PICKER_LIST,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createMemo, createSignal, For, Show } from "solid-js";
|
|
2
2
|
import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
|
|
3
|
-
import { STAGGER } from "../lib/motion-classes.js";
|
|
4
3
|
import { PICKER_LIST } from "../lib/picker-classes.js";
|
|
5
4
|
import { CHIP, ICON_PILL_TINT } from "../lib/pill-classes.js";
|
|
6
5
|
import { cn } from "../lib/utils.js";
|
|
@@ -427,7 +426,7 @@ export function IconPicker(props: IconPickerProps) {
|
|
|
427
426
|
<Show when={!loading() && search().trim() && displayIcons().length === 0}>
|
|
428
427
|
<div class="text-muted-foreground py-4 text-center text-sm">No icons found</div>
|
|
429
428
|
</Show>
|
|
430
|
-
<div class=
|
|
429
|
+
<div class="grid grid-cols-6 gap-1">
|
|
431
430
|
<For each={displayIcons()}>
|
|
432
431
|
{(icon) => (
|
|
433
432
|
<button
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
Show,
|
|
9
9
|
Switch,
|
|
10
10
|
} from "solid-js";
|
|
11
|
-
import {
|
|
11
|
+
import { focusedIn, focusWithoutTracking } from "../lib/behavior/focus-scope.js";
|
|
12
12
|
import { FIELD_CHROME } from "../lib/input-classes.js";
|
|
13
13
|
import { PICKER_LIST } from "../lib/picker-classes.js";
|
|
14
14
|
import { SECTION_INNER_RADIUS } from "../lib/section-tokens.js";
|
|
@@ -220,7 +220,7 @@ function ImageGallery(
|
|
|
220
220
|
|
|
221
221
|
// A control that disables or leaves drops focus to the page, which a sealed dialog's trap moves outside, closing the gallery.
|
|
222
222
|
const holdFocus = () => focusWithoutTracking(panel);
|
|
223
|
-
const focused = () => (panel ?
|
|
223
|
+
const focused = () => (panel ? focusedIn(panel) : null);
|
|
224
224
|
const focusLost = () => {
|
|
225
225
|
const at = focused();
|
|
226
226
|
return !at || at === document.body;
|
package/src/solid/menu-parts.tsx
CHANGED
|
@@ -29,7 +29,6 @@ import {
|
|
|
29
29
|
MENU_LABEL,
|
|
30
30
|
MENU_SEPARATOR,
|
|
31
31
|
} from "../lib/menu-classes.js";
|
|
32
|
-
import { STAGGER } from "../lib/motion-classes.js";
|
|
33
32
|
import { FLOATING_PANEL } from "../lib/overlay-classes.js";
|
|
34
33
|
import { cn } from "../lib/utils.js";
|
|
35
34
|
import { Icon } from "./icon.js";
|
|
@@ -43,7 +42,7 @@ const MENU_CONTENT_CLASS = cn(FLOATING_PANEL, "min-w-[8rem] overflow-hidden p-1"
|
|
|
43
42
|
/** Every menu content and sub content wraps its rows in one selection scope, keyed off the highlighted row. */
|
|
44
43
|
const MenuContentIndicator: ParentComponent = (props) => (
|
|
45
44
|
// The one element between role="menu" and its rows: an unnamed div there breaks the menu's ownership in the a11y tree.
|
|
46
|
-
<SelectionScope role="none"
|
|
45
|
+
<SelectionScope role="none" marker="highlighted" radius={MENU_ITEM_RADIUS}>
|
|
47
46
|
{props.children}
|
|
48
47
|
</SelectionScope>
|
|
49
48
|
);
|
|
@@ -269,18 +268,6 @@ function toneStyle(tone: string | undefined) {
|
|
|
269
268
|
return tone ? { "--selection-tone": tone, color: glassToneText(tone) } : undefined;
|
|
270
269
|
}
|
|
271
270
|
|
|
272
|
-
/* True order among the menu's rows, labels and separators, for the stagger:
|
|
273
|
-
* nth-child restarts inside a group, the DOM order does not. Refs fire before
|
|
274
|
-
* insertion, hence the microtask. */
|
|
275
|
-
function writeRowIndex(el: HTMLElement) {
|
|
276
|
-
queueMicrotask(() => {
|
|
277
|
-
const menu = el.closest('[role="menu"], [role="listbox"]');
|
|
278
|
-
if (!menu) return;
|
|
279
|
-
const i = Array.from(menu.querySelectorAll("[data-stagger-row]")).indexOf(el);
|
|
280
|
-
if (i >= 0) el.style.setProperty("--i", String(i));
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
|
|
284
271
|
interface RowOwnProps {
|
|
285
272
|
disabled?: boolean;
|
|
286
273
|
closeOnSelect?: boolean;
|
|
@@ -392,7 +379,6 @@ function MenuRow(props: MenuRowPartProps): JSX.Element {
|
|
|
392
379
|
as: local.as,
|
|
393
380
|
defaultAs: "div" as ValidComponent,
|
|
394
381
|
ref: (el: HTMLElement) => {
|
|
395
|
-
writeRowIndex(el);
|
|
396
382
|
submenu?.menu.setTrigger(el);
|
|
397
383
|
if (typeof local.ref === "function") local.ref(el);
|
|
398
384
|
},
|
|
@@ -434,7 +420,6 @@ function MenuRow(props: MenuRowPartProps): JSX.Element {
|
|
|
434
420
|
get "data-indeterminate"() {
|
|
435
421
|
return indeterminate() ? "" : undefined;
|
|
436
422
|
},
|
|
437
|
-
"data-stagger-row": "",
|
|
438
423
|
get "data-slot"() {
|
|
439
424
|
return local.slotName;
|
|
440
425
|
},
|
|
@@ -511,14 +496,12 @@ export const MenuLabelPart: Component<MenuLabelProps & { slotName: string }> = (
|
|
|
511
496
|
as: local.as,
|
|
512
497
|
defaultAs: "span" as ValidComponent,
|
|
513
498
|
ref: (el: HTMLElement) => {
|
|
514
|
-
writeRowIndex(el);
|
|
515
499
|
if (typeof local.ref === "function") local.ref(el);
|
|
516
500
|
},
|
|
517
501
|
get id() {
|
|
518
502
|
return id();
|
|
519
503
|
},
|
|
520
504
|
"aria-hidden": "true",
|
|
521
|
-
"data-stagger-row": "",
|
|
522
505
|
get "data-slot"() {
|
|
523
506
|
return local.slotName;
|
|
524
507
|
},
|
|
@@ -598,11 +581,9 @@ export const MenuSeparatorPart: Component<MenuSeparatorProps> = (props) => {
|
|
|
598
581
|
<hr
|
|
599
582
|
{...rest}
|
|
600
583
|
ref={(el) => {
|
|
601
|
-
writeRowIndex(el);
|
|
602
584
|
if (typeof local.ref === "function") local.ref(el);
|
|
603
585
|
}}
|
|
604
586
|
data-orientation="horizontal"
|
|
605
|
-
data-stagger-row=""
|
|
606
587
|
data-slot={local.slotName}
|
|
607
588
|
class={cn(MENU_SEPARATOR, local.class)}
|
|
608
589
|
/>
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
useContext,
|
|
10
10
|
} from "solid-js";
|
|
11
11
|
import { CARD_SURFACE } from "../lib/card-classes.js";
|
|
12
|
-
import { STAGGER } from "../lib/motion-classes.js";
|
|
13
12
|
import { cn } from "../lib/utils.js";
|
|
14
13
|
import { Icon } from "./icon.js";
|
|
15
14
|
import { Ornament } from "./ornament.js";
|
|
@@ -30,7 +29,7 @@ const OPTION_CHOICE_ROW =
|
|
|
30
29
|
"rounded-sm text-foreground/75 transition-colors duration-(--duration-state) hover:bg-foreground/5 aria-checked:text-foreground";
|
|
31
30
|
|
|
32
31
|
const OPTION_CARD_DRAWER_CONTENT =
|
|
33
|
-
"-translate-y-2 flex flex-col gap-0.5 pr-1 pb-2 pl-[calc(var(--spacing)*3.5+54px)] opacity-0 transition-[opacity,translate] duration-(--duration-expand) ease-(--ease-morph) group-data-[checked]/option-card:translate-y-0 group-data-[checked]/option-card:opacity-100
|
|
32
|
+
"-translate-y-2 flex flex-col gap-0.5 pr-1 pb-2 pl-[calc(var(--spacing)*3.5+54px)] opacity-0 transition-[opacity,translate] duration-(--duration-expand) ease-(--ease-morph) group-data-[checked]/option-card:translate-y-0 group-data-[checked]/option-card:opacity-100";
|
|
34
33
|
|
|
35
34
|
/* Sub-options are rows of the card, chosen in place: the same row a picker
|
|
36
35
|
* list shows, flat on the card (a glass pill on a glass card is a layer too
|
|
@@ -182,7 +181,6 @@ export function OptionCard(props: {
|
|
|
182
181
|
role={choices().length > 0 ? "radiogroup" : "group"}
|
|
183
182
|
aria-label={`${props.title} options`}
|
|
184
183
|
class={OPTION_CARD_DRAWER_CONTENT}
|
|
185
|
-
classList={{ [STAGGER]: checked() }}
|
|
186
184
|
>
|
|
187
185
|
{kids()}
|
|
188
186
|
</div>
|
package/src/solid/popover.tsx
CHANGED
|
@@ -18,7 +18,12 @@ import { type Align, controlRadius, type Side } from "../lib/anchor-placement.js
|
|
|
18
18
|
import { createAnchored } from "../lib/behavior/anchored.js";
|
|
19
19
|
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
20
20
|
import { createDismiss } from "../lib/behavior/dismiss.js";
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
createFocusScope,
|
|
23
|
+
focusedIn,
|
|
24
|
+
focusFell,
|
|
25
|
+
focusWithoutTracking,
|
|
26
|
+
} from "../lib/behavior/focus-scope.js";
|
|
22
27
|
import { createHideOutside } from "../lib/behavior/hide-outside.js";
|
|
23
28
|
import { registerLayer } from "../lib/behavior/layer-stack.js";
|
|
24
29
|
import {
|
|
@@ -33,7 +38,7 @@ import { createPresence } from "../lib/behavior/presence.js";
|
|
|
33
38
|
import { effect, merge } from "../lib/behavior/solid.js";
|
|
34
39
|
import { INPUT_SURFACE } from "../lib/input-classes.js";
|
|
35
40
|
import { nestedLayerAttrs, Z_CLASS } from "../lib/layers.js";
|
|
36
|
-
import { FIELD_MOTION, MORPH_MOTION, MOTION_EXIT_MS
|
|
41
|
+
import { FIELD_MOTION, MORPH_MOTION, MOTION_EXIT_MS } from "../lib/motion-classes.js";
|
|
37
42
|
import { FLOATING_PANEL } from "../lib/overlay-classes.js";
|
|
38
43
|
import { inShadowRoot } from "../lib/shadow-layer.js";
|
|
39
44
|
import { cn } from "../lib/utils.js";
|
|
@@ -49,7 +54,7 @@ const ANCHOR_WIDTH = "--kb-popper-anchor-width";
|
|
|
49
54
|
* by the panel, so the panel edge and the trigger edge are one rectangle. */
|
|
50
55
|
const FIELD_PANEL = `${INPUT_SURFACE} ${FIELD_MOTION} relative ${Z_CLASS.overlay} w-[var(--kb-popper-anchor-width)] overflow-hidden rounded-md text-popover-foreground outline-hidden`;
|
|
51
56
|
|
|
52
|
-
const OVERLAY_PANEL = `${FLOATING_PANEL} ${MORPH_MOTION}
|
|
57
|
+
const OVERLAY_PANEL = `${FLOATING_PANEL} ${MORPH_MOTION} w-72 p-4`;
|
|
53
58
|
|
|
54
59
|
interface PopoverProps {
|
|
55
60
|
open?: boolean;
|
|
@@ -250,13 +255,6 @@ interface PopoverContentProps extends Omit<ComponentProps<"div">, "ref"> {
|
|
|
250
255
|
forceMount?: boolean;
|
|
251
256
|
}
|
|
252
257
|
|
|
253
|
-
function focusLostFrom(panel: HTMLElement): boolean {
|
|
254
|
-
const page = document.activeElement;
|
|
255
|
-
if (!page || page === document.body) return true;
|
|
256
|
-
const active = activeOf(panel);
|
|
257
|
-
return active !== null && panel.contains(active);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
258
|
const PopoverContent: Component<PopoverContentProps> = (props) => {
|
|
261
259
|
const ctx = usePopover();
|
|
262
260
|
const [local, rest] = splitProps(props, [
|
|
@@ -351,7 +349,7 @@ const PopoverContent: Component<PopoverContentProps> = (props) => {
|
|
|
351
349
|
initialFocus: (container) => {
|
|
352
350
|
if (!vetoed(local.onOpenAutoFocus, new Event("openautofocus", { cancelable: true })))
|
|
353
351
|
return null;
|
|
354
|
-
const active =
|
|
352
|
+
const active = focusedIn(container);
|
|
355
353
|
return active instanceof HTMLElement && container.contains(active) ? active : container;
|
|
356
354
|
},
|
|
357
355
|
});
|
|
@@ -379,7 +377,7 @@ const PopoverContent: Component<PopoverContentProps> = (props) => {
|
|
|
379
377
|
}
|
|
380
378
|
// After the press's own focus change: the trigger takes focus only if nothing else did.
|
|
381
379
|
setTimeout(() => {
|
|
382
|
-
if (trigger.isConnected &&
|
|
380
|
+
if (trigger.isConnected && focusFell(from)) focusWithoutTracking(trigger);
|
|
383
381
|
}, 0);
|
|
384
382
|
},
|
|
385
383
|
);
|
package/src/solid/select.tsx
CHANGED
|
@@ -21,7 +21,7 @@ import { ButtonRoot, type ButtonRootProps } from "../lib/behavior/button-root.js
|
|
|
21
21
|
import { createCollection, createTypeahead } from "../lib/behavior/collection.js";
|
|
22
22
|
import { createControllableSignal } from "../lib/behavior/controllable.js";
|
|
23
23
|
import { createDismiss } from "../lib/behavior/dismiss.js";
|
|
24
|
-
import { focusWithoutTracking } from "../lib/behavior/focus-scope.js";
|
|
24
|
+
import { focusFell, focusWithoutTracking } from "../lib/behavior/focus-scope.js";
|
|
25
25
|
import { registerLayer } from "../lib/behavior/layer-stack.js";
|
|
26
26
|
import {
|
|
27
27
|
type InteractOutsideEvent,
|
|
@@ -34,7 +34,7 @@ import { effect, merge } from "../lib/behavior/solid.js";
|
|
|
34
34
|
import { CONTROL_H, INPUT_SURFACE } from "../lib/input-classes.js";
|
|
35
35
|
import { nestedLayerAttrs, Z_CLASS } from "../lib/layers.js";
|
|
36
36
|
import { MENU_ITEM, MENU_ITEM_RADIUS, MENU_LABEL, MENU_SEPARATOR } from "../lib/menu-classes.js";
|
|
37
|
-
import { FIELD_MOTION, MOTION_EXIT_MS
|
|
37
|
+
import { FIELD_MOTION, MOTION_EXIT_MS } from "../lib/motion-classes.js";
|
|
38
38
|
import { PICKER_LIST, PICKER_TRIGGER } from "../lib/picker-classes.js";
|
|
39
39
|
import { cn } from "../lib/utils.js";
|
|
40
40
|
import { Icon } from "./icon.js";
|
|
@@ -191,19 +191,8 @@ const useSelectList = (): SelectListValue => {
|
|
|
191
191
|
|
|
192
192
|
const ITEM = '[role="option"][data-key]';
|
|
193
193
|
const TAP_SLOP_PX = 10;
|
|
194
|
-
const SHADOW_ROOT_NODE = 11;
|
|
195
|
-
|
|
196
194
|
const flag = (on: boolean) => (on ? "" : undefined);
|
|
197
195
|
|
|
198
|
-
function focusFellToPage(near: Element): boolean {
|
|
199
|
-
const root = near.getRootNode();
|
|
200
|
-
const shadow = root.nodeType === SHADOW_ROOT_NODE ? (root as ShadowRoot) : undefined;
|
|
201
|
-
const active = shadow ? shadow.activeElement : document.activeElement;
|
|
202
|
-
if (active && active !== document.body) return false;
|
|
203
|
-
const outer = document.activeElement;
|
|
204
|
-
return !outer || outer === document.body || outer === shadow?.host;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
196
|
function read<T, V>(option: T, by: Field<T, V> | undefined): unknown {
|
|
208
197
|
if (by === undefined || option === null || option === undefined) return undefined;
|
|
209
198
|
if (typeof by === "function") return by(option as Exclude<T, null>);
|
|
@@ -375,7 +364,7 @@ function Select<Option, OptGroup = never>(props: SelectProps<Option, OptGroup>):
|
|
|
375
364
|
const near = trigger();
|
|
376
365
|
if (!refocusIfLost || !near) return;
|
|
377
366
|
refocusIfLost = false;
|
|
378
|
-
if (
|
|
367
|
+
if (focusFell(near)) focusTrigger();
|
|
379
368
|
},
|
|
380
369
|
setCloseAutoFocus: (handler) => {
|
|
381
370
|
closeAutoFocus = handler;
|
|
@@ -883,7 +872,7 @@ const SelectContent: Component<SelectContentProps> = (props) => {
|
|
|
883
872
|
aria-labelledby={ctx.listboxLabelledBy()}
|
|
884
873
|
aria-multiselectable={ctx.multiple() ? "true" : undefined}
|
|
885
874
|
aria-activedescendant={ctx.optionId(collection.highlighted())}
|
|
886
|
-
class={
|
|
875
|
+
class={local.listboxClass}
|
|
887
876
|
on:keydown={onKeyDown}
|
|
888
877
|
on:pointerdown={onPointerDown}
|
|
889
878
|
on:pointermove={onPointerMove}
|
package/src/solid/selection.tsx
CHANGED
|
@@ -72,11 +72,25 @@ const DEFORM_MAX = 0.14;
|
|
|
72
72
|
/** Centre and size in the scope's own content pixels. */
|
|
73
73
|
type Box = { x: number; y: number; width: number; height: number };
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
/** The root's place on screen and its scale, which a transformed ancestor sets. */
|
|
76
|
+
function frameOf(root: HTMLElement) {
|
|
76
77
|
const outer = root.getBoundingClientRect();
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
78
|
+
const width = root.offsetWidth;
|
|
79
|
+
const height = root.offsetHeight;
|
|
80
|
+
return {
|
|
81
|
+
outer,
|
|
82
|
+
sx: width > 0 ? outer.width / width : 1,
|
|
83
|
+
sy: height > 0 ? outer.height / height : 1,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function boxIn(
|
|
88
|
+
root: HTMLElement,
|
|
89
|
+
rect: DOMRect,
|
|
90
|
+
size: { width: number; height: number },
|
|
91
|
+
frame = frameOf(root),
|
|
92
|
+
): Box {
|
|
93
|
+
const { outer, sx, sy } = frame;
|
|
80
94
|
return {
|
|
81
95
|
x: (rect.left + rect.width / 2 - outer.left) / sx - root.clientLeft + root.scrollLeft,
|
|
82
96
|
y: (rect.top + rect.height / 2 - outer.top) / sy - root.clientTop + root.scrollTop,
|
|
@@ -87,26 +101,27 @@ function boxIn(root: HTMLElement, el: Element, size: { width: number; height: nu
|
|
|
87
101
|
|
|
88
102
|
function itemBox(root: HTMLElement, item: HTMLElement): Box | undefined {
|
|
89
103
|
if (!item.isConnected) return undefined;
|
|
90
|
-
const
|
|
104
|
+
const size = { width: item.offsetWidth, height: item.offsetHeight };
|
|
105
|
+
const box = boxIn(root, item.getBoundingClientRect(), size);
|
|
91
106
|
return box.width > 0 && box.height > 0 ? box : undefined;
|
|
92
107
|
}
|
|
93
108
|
|
|
94
109
|
/** Whether the box shows inside the root's scrollport; a highlight never flies in from out of sight. */
|
|
95
110
|
function inSight(root: HTMLElement, box: Box): boolean {
|
|
111
|
+
const top = root.scrollTop;
|
|
112
|
+
const left = root.scrollLeft;
|
|
96
113
|
return (
|
|
97
|
-
box.y + box.height / 2 >
|
|
98
|
-
box.y - box.height / 2 <
|
|
99
|
-
box.x + box.width / 2 >
|
|
100
|
-
box.x - box.width / 2 <
|
|
114
|
+
box.y + box.height / 2 > top &&
|
|
115
|
+
box.y - box.height / 2 < top + root.clientHeight &&
|
|
116
|
+
box.x + box.width / 2 > left &&
|
|
117
|
+
box.x - box.width / 2 < left + root.clientWidth
|
|
101
118
|
);
|
|
102
119
|
}
|
|
103
120
|
|
|
104
121
|
function flyerBox(root: HTMLElement, flyer: HTMLElement): Box {
|
|
105
|
-
const
|
|
106
|
-
const sx = root.offsetWidth > 0 ? outer.width / root.offsetWidth : 1;
|
|
107
|
-
const sy = root.offsetHeight > 0 ? outer.height / root.offsetHeight : 1;
|
|
122
|
+
const frame = frameOf(root);
|
|
108
123
|
const rect = flyer.getBoundingClientRect();
|
|
109
|
-
return boxIn(root,
|
|
124
|
+
return boxIn(root, rect, { width: rect.width / frame.sx, height: rect.height / frame.sy }, frame);
|
|
110
125
|
}
|
|
111
126
|
|
|
112
127
|
function highlightOf(item: Element): Element | null {
|