@glasshome/ui 1.32.0 → 1.33.0

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.
@@ -0,0 +1 @@
1
+ export declare function installSettledAnimations(): void;
@@ -0,0 +1 @@
1
+ export declare function installDenyFetch(): void;
@@ -0,0 +1,5 @@
1
+ import { vi } from "vitest";
2
+ export declare function useFakeTime(config?: {
3
+ toFake?: NonNullable<Parameters<typeof vi.useFakeTimers>[0]>["toFake"];
4
+ }): void;
5
+ export declare function useSystemTime(at: number | Date): void;
@@ -0,0 +1,3 @@
1
+ export { installSettledAnimations } from "./animations.js";
2
+ export { useFakeTime, useSystemTime } from "./fake-time.js";
3
+ export { installDenyFetch } from "./deny-fetch.js";
@@ -0,0 +1,39 @@
1
+ import { afterEach as e, onTestFinished as t, vi as n } from "vitest";
2
+ //#region src/testing/animations.ts
3
+ function r() {
4
+ let e = window.getComputedStyle.bind(window);
5
+ window.getComputedStyle = ((t, n) => {
6
+ let r = e(t, n);
7
+ return r.animationName ? r : new Proxy(r, { get: (e, t) => {
8
+ if (t === "animationName") return "none";
9
+ let n = Reflect.get(e, t);
10
+ return typeof n == "function" ? n.bind(e) : n;
11
+ } });
12
+ });
13
+ }
14
+ //#endregion
15
+ //#region src/testing/fake-time.ts
16
+ function i(e) {
17
+ n.useFakeTimers(e), t(() => {
18
+ n.useRealTimers();
19
+ });
20
+ }
21
+ function a(e) {
22
+ n.useFakeTimers({ toFake: ["Date"] }), n.setSystemTime(e), t(() => {
23
+ n.useRealTimers();
24
+ });
25
+ }
26
+ //#endregion
27
+ //#region src/testing/deny-fetch.ts
28
+ function o() {
29
+ let t = [];
30
+ globalThis.fetch = Object.assign((e) => {
31
+ let n = e instanceof Request ? e.url : String(e);
32
+ return t.push(n), Promise.reject(/* @__PURE__ */ Error(`fetch denied in tests: stub the route for ${n}`));
33
+ }, { preconnect: () => {} }), e(() => {
34
+ let e = t;
35
+ if (t = [], e.length > 0) throw Error(`unstubbed fetch: ${[...new Set(e)].join(", ")}`);
36
+ });
37
+ }
38
+ //#endregion
39
+ export { o as installDenyFetch, r as installSettledAnimations, i as useFakeTime, a as useSystemTime };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/ui",
3
- "version": "1.32.0",
3
+ "version": "1.33.0",
4
4
  "description": "SolidJS component library for GlassHome, built on Kobalte",
5
5
  "keywords": [
6
6
  "components",
@@ -29,6 +29,7 @@
29
29
  "src/lib",
30
30
  "src/solid",
31
31
  "src/styles",
32
+ "src/testing",
32
33
  "src/tokens",
33
34
  "scripts",
34
35
  "SPEC.md"
@@ -59,6 +60,11 @@
59
60
  "./package.json": "./package.json",
60
61
  "./styles/theme": "./src/styles/theme.css",
61
62
  "./scripts/*": "./scripts/*",
63
+ "./testing": {
64
+ "@glasshome/source": "./src/testing/index.ts",
65
+ "types": "./dist/testing/index.d.ts",
66
+ "import": "./dist/testing/index.js"
67
+ },
62
68
  "./backgrounds": {
63
69
  "@glasshome/source": "./src/backgrounds/index.ts",
64
70
  "types": "./dist/backgrounds/index.d.ts",
@@ -122,7 +128,13 @@
122
128
  "peerDependencies": {
123
129
  "solid-js": "^1.9.9",
124
130
  "tailwindcss": "^4.1.13",
125
- "tw-animate-css": "^1.4.0"
131
+ "tw-animate-css": "^1.4.0",
132
+ "vitest": "^4.1.10"
133
+ },
134
+ "peerDependenciesMeta": {
135
+ "vitest": {
136
+ "optional": true
137
+ }
126
138
  },
127
139
  "engines": {
128
140
  "node": ">=20"
@@ -0,0 +1,12 @@
1
+ export async function whenAnimationsSettle(
2
+ el: Element,
3
+ options: { subtree?: boolean; filter?: (animation: Animation) => boolean } = {},
4
+ ): Promise<void> {
5
+ // One microtask so styles written in the same tick start their animations first.
6
+ await Promise.resolve();
7
+ if (typeof el.getAnimations !== "function") return;
8
+ const all = el.getAnimations({ subtree: options.subtree ?? false });
9
+ const running = options.filter ? all.filter(options.filter) : all;
10
+ if (running.length === 0) return;
11
+ await Promise.allSettled(running.map((animation) => animation.finished));
12
+ }
@@ -18,6 +18,8 @@ import { Dynamic, Portal } from "solid-js/web";
18
18
  import { Z } from "../../lib/layers.js";
19
19
  import { OVERLAY_SURFACE_OPAQUE } from "../../lib/overlay-classes.js";
20
20
  import { cn } from "../../lib/utils.js";
21
+ import { whenAnimationsSettle } from "../../lib/when-animations-settle.js";
22
+ import { isSheetMotion } from "./sheet-motion.js";
21
23
  import {
22
24
  callEventHandler,
23
25
  createModalLabels,
@@ -216,25 +218,22 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
216
218
  el.style.transform = "";
217
219
  };
218
220
 
219
- const onAnimationEnd = (e: AnimationEvent) => {
220
- if (e.target !== el) return;
221
- const s = ctx.state();
222
- if (s === "opening" && e.animationName === "bs-slide-up") ctx.setState("open");
223
- else if (s === "closing" && e.animationName === "bs-slide-down") ctx.setState("closed");
224
- };
225
-
226
- const onTransitionEnd = (e: TransitionEvent) => {
227
- if (e.target !== el) return;
228
- if (e.propertyName !== "transform") return;
221
+ createEffect(() => {
229
222
  const s = ctx.state();
230
- if (s === "snapping") {
231
- ctx.setState("open");
232
- clearAnimInline();
233
- } else if (s === "closing") {
234
- ctx.setState("closed");
235
- clearAnimInline();
236
- }
237
- };
223
+ if (s !== "opening" && s !== "closing" && s !== "snapping") return;
224
+ const node = el;
225
+ if (!node) return;
226
+ let stale = false;
227
+ onCleanup(() => (stale = true));
228
+ void whenAnimationsSettle(node, { filter: isSheetMotion }).then(() => {
229
+ if (stale) return;
230
+ if (s === "opening") ctx.setState("open");
231
+ else {
232
+ ctx.setState(s === "snapping" ? "open" : "closed");
233
+ clearAnimInline();
234
+ }
235
+ });
236
+ });
238
237
 
239
238
  createEffect(() => {
240
239
  const node = ctx.contentRef();
@@ -352,8 +351,6 @@ const BottomSheetContent: ParentComponent<BottomSheetContentProps> = (props) =>
352
351
  data-sheet-content=""
353
352
  data-state={ctx.state()}
354
353
  data-reduced-motion={prefersReducedMotion() ? "" : undefined}
355
- onAnimationEnd={onAnimationEnd}
356
- onTransitionEnd={onTransitionEnd}
357
354
  style={{
358
355
  ...(typeof local.style === "object" ? local.style : {}),
359
356
  "z-index": Z.sheet,
@@ -0,0 +1,4 @@
1
+ export const isSheetMotion = (a: Animation) =>
2
+ "animationName" in a
3
+ ? a.animationName === "bs-slide-up" || a.animationName === "bs-slide-down"
4
+ : "transitionProperty" in a && a.transitionProperty === "transform";
@@ -53,6 +53,8 @@ interface DockIconButtonProps extends ComponentProps<"button"> {
53
53
  badge?: number;
54
54
  }
55
55
 
56
+ const DOCK_PAGE_MS = 300;
57
+
56
58
  const DockIconButton: Component<DockIconButtonProps> = (props) => {
57
59
  // Kobalte's button root narrows `type`; Solid's ComponentProps<"button"> also
58
60
  // admits "menu", so it is split off rather than spread.
@@ -221,7 +223,7 @@ const Dock: Component<DockProps> = (props) => {
221
223
  Math.floor(((point.x - surface.left) / surface.width) * pages()),
222
224
  );
223
225
  if (target === page()) return;
224
- const timer = setTimeout(() => goToPage(target), 300);
226
+ const timer = setTimeout(() => goToPage(target), DOCK_PAGE_MS);
225
227
  onCleanup(() => clearTimeout(timer));
226
228
  });
227
229
 
@@ -8,6 +8,8 @@ import { PickerSearch } from "./picker-search.js";
8
8
  import { PickerTrigger } from "./picker-trigger.js";
9
9
  import { Popover, PopoverAnchor, PopoverContent } from "./popover.js";
10
10
 
11
+ export const ICON_SEARCH_DEBOUNCE_MS = 300;
12
+
11
13
  const ICON_LIBRARIES = [
12
14
  { prefix: "", label: "All" },
13
15
  { prefix: "mdi", label: "MDI" },
@@ -296,7 +298,7 @@ export function IconPicker(props: IconPickerProps) {
296
298
  } finally {
297
299
  setLoading(false);
298
300
  }
299
- }, 300);
301
+ }, ICON_SEARCH_DEBOUNCE_MS);
300
302
  };
301
303
 
302
304
  const defaultIcons = createMemo(() => {
@@ -0,0 +1,16 @@
1
+ // happy-dom reports animationName as "", which solid-presence reads as an animation that never ends.
2
+ export function installSettledAnimations(): void {
3
+ const realGetComputedStyle = window.getComputedStyle.bind(window);
4
+
5
+ window.getComputedStyle = ((el: Element, pseudo?: string | null) => {
6
+ const style = realGetComputedStyle(el, pseudo);
7
+ if (style.animationName) return style;
8
+ return new Proxy(style, {
9
+ get: (target, key) => {
10
+ if (key === "animationName") return "none";
11
+ const value = Reflect.get(target, key);
12
+ return typeof value === "function" ? value.bind(target) : value;
13
+ },
14
+ });
15
+ }) as typeof window.getComputedStyle;
16
+ }
@@ -0,0 +1,19 @@
1
+ import { afterEach } from "vitest";
2
+
3
+ export function installDenyFetch(): void {
4
+ let denied: string[] = [];
5
+
6
+ const deny = (input: URL | RequestInfo): Promise<Response> => {
7
+ const url = input instanceof Request ? input.url : String(input);
8
+ denied.push(url);
9
+ return Promise.reject(new Error(`fetch denied in tests: stub the route for ${url}`));
10
+ };
11
+
12
+ globalThis.fetch = Object.assign(deny, { preconnect: () => {} });
13
+
14
+ afterEach(() => {
15
+ const urls = denied;
16
+ denied = [];
17
+ if (urls.length > 0) throw new Error(`unstubbed fetch: ${[...new Set(urls)].join(", ")}`);
18
+ });
19
+ }
@@ -0,0 +1,18 @@
1
+ import { onTestFinished, vi } from "vitest";
2
+
3
+ export function useFakeTime(config?: {
4
+ toFake?: NonNullable<Parameters<typeof vi.useFakeTimers>[0]>["toFake"];
5
+ }): void {
6
+ vi.useFakeTimers(config);
7
+ onTestFinished(() => {
8
+ vi.useRealTimers();
9
+ });
10
+ }
11
+
12
+ export function useSystemTime(at: number | Date): void {
13
+ vi.useFakeTimers({ toFake: ["Date"] });
14
+ vi.setSystemTime(at);
15
+ onTestFinished(() => {
16
+ vi.useRealTimers();
17
+ });
18
+ }
@@ -0,0 +1,3 @@
1
+ export { installSettledAnimations } from "./animations.js";
2
+ export { useFakeTime, useSystemTime } from "./fake-time.js";
3
+ export { installDenyFetch } from "./deny-fetch.js";