@glasshome/ui 1.34.2 → 1.35.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.
Files changed (37) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/solid/index.js +4029 -3949
  3. package/dist/solid/radio-group.d.ts +2 -1
  4. package/dist/solid/section-card.d.ts +2 -0
  5. package/dist/solid/settings-row.d.ts +4 -0
  6. package/dist/testing/happy-dom-fidelity.d.ts +2 -0
  7. package/dist/testing/index.d.ts +1 -0
  8. package/dist/testing/index.js +64 -1
  9. package/dist/{utils-GYi7-pG_.js → utils-BhU5YZKh.js} +1 -0
  10. package/package.json +4 -3
  11. package/src/lib/clipboard.ts +2 -0
  12. package/src/solid/alert.tsx +36 -18
  13. package/src/solid/area-picker.tsx +9 -1
  14. package/src/solid/bottom-sheet/scroll-lock.ts +2 -0
  15. package/src/solid/checkbox.tsx +22 -7
  16. package/src/solid/data-table.tsx +16 -10
  17. package/src/solid/dialog-parts.tsx +7 -4
  18. package/src/solid/field.tsx +9 -5
  19. package/src/solid/icon.tsx +4 -1
  20. package/src/solid/image-picker.tsx +8 -1
  21. package/src/solid/option-card.tsx +4 -2
  22. package/src/solid/page-header.tsx +10 -7
  23. package/src/solid/password-input.tsx +5 -3
  24. package/src/solid/picker-row.tsx +14 -5
  25. package/src/solid/picker-search.tsx +9 -2
  26. package/src/solid/preview-tile.tsx +4 -2
  27. package/src/solid/radio-group.tsx +27 -7
  28. package/src/solid/schema-form.tsx +16 -3
  29. package/src/solid/section-card.tsx +42 -23
  30. package/src/solid/settings-row.tsx +20 -6
  31. package/src/solid/sheet.tsx +11 -7
  32. package/src/solid/sonner.tsx +17 -7
  33. package/src/solid/widget-card.tsx +5 -4
  34. package/src/styles/globals.css +32 -0
  35. package/src/styles/theme.css +1 -1
  36. package/src/testing/happy-dom-fidelity.ts +105 -0
  37. package/src/testing/index.ts +1 -0
@@ -0,0 +1,105 @@
1
+ const INSTALLED = Symbol.for("glasshome.happyDomFidelity");
2
+ const RECORDED = Symbol.for("glasshome.shadowRoots");
3
+
4
+ type Recorder = { [RECORDED]?: WeakMap<Element, ShadowRoot> };
5
+
6
+ function getterOf(proto: object, name: string): (event: Event) => unknown {
7
+ const get: unknown = Reflect.getOwnPropertyDescriptor(proto, name)?.get;
8
+ if (typeof get !== "function") throw new Error(`happy-dom's Event has no ${name} getter`);
9
+ return (event) => Reflect.apply(get, event, []);
10
+ }
11
+
12
+ function rootsAround(target: unknown): ShadowRoot[] {
13
+ const roots: ShadowRoot[] = [];
14
+ for (
15
+ let root = target instanceof Node ? target.getRootNode() : undefined;
16
+ root instanceof ShadowRoot;
17
+ root = root.host.getRootNode()
18
+ ) {
19
+ roots.push(root);
20
+ }
21
+ return roots;
22
+ }
23
+
24
+ function retarget(target: unknown, viewer: unknown): unknown {
25
+ const viewerRoots = rootsAround(viewer);
26
+ let node = target;
27
+ while (node instanceof Node) {
28
+ const root = node.getRootNode();
29
+ if (!(root instanceof ShadowRoot) || viewerRoots.includes(root)) return node;
30
+ node = root.host;
31
+ }
32
+ return node;
33
+ }
34
+
35
+ function hiddenFrom(node: unknown, viewer: unknown): boolean {
36
+ const viewerRoots = rootsAround(viewer);
37
+ return rootsAround(node).some((root) => root.mode === "closed" && !viewerRoots.includes(root));
38
+ }
39
+
40
+ function dispatchFlag(): (event: Event) => boolean {
41
+ const symbol = Object.getOwnPropertySymbols(new Event("probe")).find(
42
+ (key) => key.description === "dispatching",
43
+ );
44
+ if (!symbol) throw new Error("happy-dom's Event has no dispatching flag");
45
+ return (event) => Reflect.get(event, symbol) === true;
46
+ }
47
+
48
+ function installEventRetargeting(): void {
49
+ const proto = Event.prototype;
50
+ const composedPath = Reflect.get(proto, "composedPath") as (this: Event) => EventTarget[];
51
+ const rawTarget = getterOf(proto, "target");
52
+ // Solid redefines `currentTarget` on the events it delegates; the listener's own is on the prototype.
53
+ const rawCurrentTarget = getterOf(proto, "currentTarget");
54
+ const dispatching = dispatchFlag();
55
+
56
+ proto.composedPath = function (this: Event): EventTarget[] {
57
+ if (!dispatching(this)) return [];
58
+ const path = composedPath.call(this);
59
+ const viewer = rawCurrentTarget(this);
60
+ // happy-dom builds its dispatch path from this before the first listener runs.
61
+ if (!viewer) return path;
62
+ return path.filter((node) => !hiddenFrom(node, viewer));
63
+ };
64
+
65
+ Object.defineProperty(proto, "target", {
66
+ configurable: true,
67
+ get(this: Event) {
68
+ const target = rawTarget(this);
69
+ const viewer = rawCurrentTarget(this);
70
+ if (viewer) return retarget(target, viewer);
71
+ if (dispatching(this)) return target;
72
+ if (!this.composed && rootsAround(target).length > 0) return null;
73
+ return retarget(target, null);
74
+ },
75
+ });
76
+ }
77
+
78
+ function installShadowRecorder(): void {
79
+ const recorded = new WeakMap<Element, ShadowRoot>();
80
+ (Element.prototype as Recorder)[RECORDED] = recorded;
81
+ const attach = Reflect.get(Element.prototype, "attachShadow") as (
82
+ this: Element,
83
+ init: ShadowRootInit,
84
+ ) => ShadowRoot;
85
+ Element.prototype.attachShadow = function (this: Element, init: ShadowRootInit) {
86
+ const root = attach.call(this, init);
87
+ recorded.set(this, root);
88
+ return root;
89
+ };
90
+ }
91
+
92
+ export function installHappyDomFidelity(): void {
93
+ // A shared-module suite runs every file's setup against the same window.
94
+ const marked = Event.prototype as { [INSTALLED]?: true };
95
+ if (marked[INSTALLED]) return;
96
+ marked[INSTALLED] = true;
97
+ installEventRetargeting();
98
+ installShadowRecorder();
99
+ }
100
+
101
+ export function shadowOf(host: Element | null | undefined): ShadowRoot | undefined {
102
+ const recorded = (Element.prototype as Recorder)[RECORDED];
103
+ if (!recorded) throw new Error("shadowOf needs installHappyDomFidelity() in the suite's setup");
104
+ return host ? recorded.get(host) : undefined;
105
+ }
@@ -1,3 +1,4 @@
1
1
  export { installSettledAnimations } from "./animations.js";
2
2
  export { useFakeTime, useSystemTime } from "./fake-time.js";
3
3
  export { installDenyFetch } from "./deny-fetch.js";
4
+ export { installHappyDomFidelity, shadowOf } from "./happy-dom-fidelity.js";