@glasshome/ui 1.41.0 → 1.43.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.
Files changed (188) hide show
  1. package/SPEC.md +5 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +3 -3
  4. package/dist/lib/anchor-placement.d.ts +34 -0
  5. package/dist/lib/balance-rows.d.ts +10 -4
  6. package/dist/lib/behavior/anchored.d.ts +26 -0
  7. package/dist/lib/behavior/button-root.d.ts +7 -0
  8. package/dist/lib/behavior/collection.d.ts +32 -0
  9. package/dist/lib/behavior/controllable.d.ts +8 -0
  10. package/dist/lib/behavior/dismiss.d.ts +13 -0
  11. package/dist/lib/behavior/focus-scope.d.ts +24 -0
  12. package/dist/lib/behavior/hide-outside.d.ts +7 -0
  13. package/dist/lib/behavior/layer-stack.d.ts +34 -0
  14. package/dist/lib/behavior/menu.d.ts +59 -0
  15. package/dist/lib/behavior/modal-root.d.ts +68 -0
  16. package/dist/lib/behavior/polymorphic.d.ts +6 -0
  17. package/dist/lib/behavior/presence.d.ts +18 -0
  18. package/dist/lib/behavior/range.d.ts +44 -0
  19. package/dist/lib/behavior/solid.d.ts +13 -0
  20. package/dist/lib/color/color.d.ts +41 -0
  21. package/dist/lib/color/index.d.ts +2 -0
  22. package/dist/lib/color/intl.d.ts +40 -0
  23. package/dist/lib/dock-slot-classes.d.ts +2 -0
  24. package/dist/lib/hold.d.ts +1 -1
  25. package/dist/lib/locale.d.ts +3 -0
  26. package/dist/lib/menu-classes.d.ts +2 -0
  27. package/dist/lib/motion-classes.d.ts +5 -2
  28. package/dist/lib/overlay-classes.d.ts +4 -0
  29. package/dist/lib/page-cover.d.ts +8 -0
  30. package/dist/lib/scroll-track.d.ts +3 -2
  31. package/dist/lib/section-tokens.d.ts +1 -1
  32. package/dist/lib/segment-classes.d.ts +2 -0
  33. package/dist/lib/shadow-layer.d.ts +0 -43
  34. package/dist/lib/toggle-set.d.ts +44 -0
  35. package/dist/lib/visually-hidden.d.ts +3 -0
  36. package/dist/solid/accordion.d.ts +35 -11
  37. package/dist/solid/alert-dialog.d.ts +5 -8
  38. package/dist/solid/avatar.d.ts +8 -4
  39. package/dist/solid/bottom-sheet/bottom-sheet.d.ts +2 -2
  40. package/dist/solid/bottom-sheet/constants.d.ts +1 -1
  41. package/dist/solid/button.d.ts +5 -4
  42. package/dist/solid/charts.d.ts +1 -1
  43. package/dist/solid/checkbox.d.ts +14 -4
  44. package/dist/solid/collapsible.d.ts +33 -5
  45. package/dist/solid/color-disc.d.ts +1 -1
  46. package/dist/solid/color-slider.d.ts +1 -1
  47. package/dist/solid/color-wheel.d.ts +1 -1
  48. package/dist/solid/context-menu.d.ts +58 -24
  49. package/dist/solid/dialog-parts.d.ts +53 -16
  50. package/dist/solid/dialog.d.ts +7 -10
  51. package/dist/solid/dropdown-menu.d.ts +55 -24
  52. package/dist/solid/empty.d.ts +1 -1
  53. package/dist/solid/form.d.ts +5 -6
  54. package/dist/solid/hover-card.d.ts +65 -9
  55. package/dist/solid/index.d.ts +5 -2
  56. package/dist/solid/index.js +8671 -14317
  57. package/dist/solid/input-group.d.ts +6 -6
  58. package/dist/solid/item.d.ts +1 -1
  59. package/dist/solid/menu-parts.d.ts +175 -24
  60. package/dist/solid/option-card.d.ts +1 -4
  61. package/dist/solid/picker-row.d.ts +2 -0
  62. package/dist/solid/popover.d.ts +77 -12
  63. package/dist/solid/progress.d.ts +11 -3
  64. package/dist/solid/radio-group.d.ts +31 -6
  65. package/dist/solid/responsive-dialog.d.ts +3 -1
  66. package/dist/solid/scroll-area.d.ts +1 -1
  67. package/dist/solid/section-card.d.ts +2 -3
  68. package/dist/solid/select.d.ts +107 -10
  69. package/dist/solid/selection.d.ts +10 -1
  70. package/dist/solid/sheet.d.ts +6 -9
  71. package/dist/solid/sliding-indicator.d.ts +1 -1
  72. package/dist/solid/sonner.d.ts +1 -1
  73. package/dist/solid/stale-veil.d.ts +7 -0
  74. package/dist/solid/tabs.d.ts +28 -9
  75. package/dist/solid/toggle-group.d.ts +30 -5
  76. package/dist/solid/toggle.d.ts +11 -3
  77. package/dist/solid/tooltip.d.ts +71 -9
  78. package/dist/tokens/index.js +54 -51
  79. package/dist/{utils-CGN4X-2O.js → utils-3Codx-NZ.js} +848 -618
  80. package/package.json +6 -7
  81. package/src/index.ts +1 -0
  82. package/src/lib/anchor-placement.ts +77 -4
  83. package/src/lib/balance-rows.ts +115 -40
  84. package/src/lib/behavior/anchored.ts +106 -0
  85. package/src/lib/behavior/button-root.tsx +103 -0
  86. package/src/lib/behavior/collection.ts +218 -0
  87. package/src/lib/behavior/controllable.ts +22 -0
  88. package/src/lib/behavior/dismiss.ts +185 -0
  89. package/src/lib/behavior/focus-scope.ts +227 -0
  90. package/src/lib/behavior/hide-outside.ts +85 -0
  91. package/src/lib/behavior/layer-stack.ts +150 -0
  92. package/src/lib/behavior/menu.ts +470 -0
  93. package/src/lib/behavior/modal-root.tsx +452 -0
  94. package/src/lib/behavior/polymorphic.tsx +30 -0
  95. package/src/lib/behavior/presence.ts +89 -0
  96. package/src/lib/behavior/range.ts +212 -0
  97. package/src/lib/behavior/solid.ts +30 -0
  98. package/src/lib/clipboard.ts +4 -4
  99. package/src/lib/color/color.ts +746 -0
  100. package/src/lib/color/index.ts +2 -0
  101. package/src/lib/color/intl.ts +60 -0
  102. package/src/lib/dock-slot-classes.ts +3 -0
  103. package/src/lib/hold.ts +1 -1
  104. package/src/lib/locale.ts +62 -0
  105. package/src/lib/menu-classes.ts +3 -0
  106. package/src/lib/motion-classes.ts +33 -8
  107. package/src/lib/overlay-classes.ts +8 -3
  108. package/src/lib/page-cover.ts +47 -0
  109. package/src/lib/scroll-track.ts +11 -6
  110. package/src/lib/section-tokens.ts +1 -1
  111. package/src/lib/segment-classes.ts +3 -0
  112. package/src/lib/shadow-layer.ts +0 -136
  113. package/src/lib/toggle-set.ts +133 -0
  114. package/src/lib/visually-hidden.ts +15 -0
  115. package/src/solid/accordion.tsx +294 -20
  116. package/src/solid/alert-dialog.tsx +36 -85
  117. package/src/solid/area-picker.tsx +5 -3
  118. package/src/solid/avatar.tsx +98 -24
  119. package/src/solid/badge.tsx +5 -5
  120. package/src/solid/bottom-sheet/bottom-sheet.tsx +73 -129
  121. package/src/solid/bottom-sheet/constants.ts +3 -1
  122. package/src/solid/bottom-sheet/drag-controller.ts +11 -0
  123. package/src/solid/breadcrumb.tsx +4 -4
  124. package/src/solid/button-group.tsx +4 -4
  125. package/src/solid/button.tsx +12 -6
  126. package/src/solid/card.tsx +5 -4
  127. package/src/solid/charts.tsx +1 -1
  128. package/src/solid/checkbox.tsx +167 -44
  129. package/src/solid/collapsible.tsx +260 -12
  130. package/src/solid/color-disc.tsx +11 -12
  131. package/src/solid/color-slider.tsx +114 -47
  132. package/src/solid/color-wheel.tsx +137 -39
  133. package/src/solid/context-menu.tsx +287 -86
  134. package/src/solid/dialog-parts.tsx +135 -46
  135. package/src/solid/dialog.tsx +44 -76
  136. package/src/solid/dock-edit.tsx +5 -4
  137. package/src/solid/dock.tsx +6 -5
  138. package/src/solid/dropdown-menu.tsx +252 -107
  139. package/src/solid/empty.tsx +1 -1
  140. package/src/solid/entity-selector.tsx +5 -3
  141. package/src/solid/face-toggle.tsx +43 -18
  142. package/src/solid/form.tsx +9 -9
  143. package/src/solid/glyph-tile.tsx +48 -21
  144. package/src/solid/hover-card.tsx +288 -21
  145. package/src/solid/icon-picker.tsx +2 -1
  146. package/src/solid/image-picker.tsx +6 -5
  147. package/src/solid/index.ts +5 -4
  148. package/src/solid/input-group.tsx +7 -5
  149. package/src/solid/input-otp.tsx +2 -1
  150. package/src/solid/item.tsx +5 -5
  151. package/src/solid/logo.tsx +5 -4
  152. package/src/solid/menu-parts.tsx +619 -145
  153. package/src/solid/option-card.tsx +6 -10
  154. package/src/solid/picker-row.tsx +10 -5
  155. package/src/solid/picker-search.tsx +2 -1
  156. package/src/solid/popover.tsx +424 -71
  157. package/src/solid/preview-tile.tsx +1 -1
  158. package/src/solid/progress.tsx +84 -15
  159. package/src/solid/radio-group.tsx +271 -34
  160. package/src/solid/responsive-dialog.tsx +10 -10
  161. package/src/solid/schema-form.tsx +1 -6
  162. package/src/solid/scroll-area.tsx +1 -1
  163. package/src/solid/section-card.tsx +3 -4
  164. package/src/solid/select.tsx +950 -95
  165. package/src/solid/selection.tsx +142 -66
  166. package/src/solid/sheet.tsx +48 -80
  167. package/src/solid/slider.tsx +115 -65
  168. package/src/solid/sliding-indicator.tsx +1 -1
  169. package/src/solid/sonner.tsx +1 -1
  170. package/src/solid/spotlight.tsx +23 -11
  171. package/src/solid/stale-veil.tsx +20 -0
  172. package/src/solid/switch.tsx +8 -6
  173. package/src/solid/tabs.tsx +377 -52
  174. package/src/solid/term.tsx +3 -4
  175. package/src/solid/toggle-group.tsx +237 -95
  176. package/src/solid/toggle.tsx +43 -9
  177. package/src/solid/tooltip.tsx +285 -26
  178. package/src/styles/globals.css +64 -10
  179. package/src/styles/theme.css +12 -4
  180. package/src/tokens/material.ts +11 -2
  181. package/dist/lib/when-animations-settle.d.ts +0 -4
  182. package/dist/solid/bottom-sheet/focus-trap.d.ts +0 -6
  183. package/dist/solid/bottom-sheet/scroll-lock.d.ts +0 -2
  184. package/dist/solid/bottom-sheet/sheet-motion.d.ts +0 -1
  185. package/src/lib/when-animations-settle.ts +0 -12
  186. package/src/solid/bottom-sheet/focus-trap.ts +0 -63
  187. package/src/solid/bottom-sheet/scroll-lock.ts +0 -66
  188. package/src/solid/bottom-sheet/sheet-motion.ts +0 -4
@@ -0,0 +1,212 @@
1
+ import { type Accessor, createMemo } from "solid-js";
2
+ import { readingDirection } from "../locale.js";
3
+ import { createControllableSignal } from "./controllable.js";
4
+
5
+ function snapValueToStep(value: number, min: number, max: number, step: number): number {
6
+ const remainder = (value - (Number.isNaN(min) ? 0 : min)) % step;
7
+ let snapped =
8
+ Math.abs(remainder) * 2 >= step
9
+ ? value + Math.sign(remainder) * (step - Math.abs(remainder))
10
+ : value - remainder;
11
+ if (!Number.isNaN(min)) {
12
+ if (snapped < min) snapped = min;
13
+ else if (!Number.isNaN(max) && snapped > max)
14
+ snapped = min + Math.floor((max - min) / step) * step;
15
+ } else if (!Number.isNaN(max) && snapped > max) {
16
+ snapped = Math.floor(max / step) * step;
17
+ }
18
+ const text = step.toString();
19
+ const point = text.indexOf(".");
20
+ const precision = point >= 0 ? text.length - point : 0;
21
+ if (precision > 0) {
22
+ const pow = 10 ** precision;
23
+ snapped = Math.round(snapped * pow) / pow;
24
+ }
25
+ return snapped;
26
+ }
27
+
28
+ const pageSizeOf = (min: number, max: number, step: number): number => {
29
+ const tenth = (max - min) / 10;
30
+ return Math.max(snapValueToStep(tenth, 0, tenth + step, step), step);
31
+ };
32
+
33
+ export type RangeKey = "decrease" | "increase" | "pageDown" | "pageUp" | "first" | "last";
34
+
35
+ const LTR_KEYS: Record<string, RangeKey> = {
36
+ ArrowLeft: "decrease",
37
+ ArrowDown: "decrease",
38
+ ArrowRight: "increase",
39
+ ArrowUp: "increase",
40
+ PageDown: "pageDown",
41
+ PageUp: "pageUp",
42
+ Home: "first",
43
+ End: "last",
44
+ };
45
+
46
+ const RTL_KEYS: Record<string, RangeKey> = {
47
+ ...LTR_KEYS,
48
+ ArrowLeft: "increase",
49
+ ArrowRight: "decrease",
50
+ };
51
+
52
+ const SHIFTED: Partial<Record<RangeKey, RangeKey>> = { decrease: "pageDown", increase: "pageUp" };
53
+
54
+ export function rangeKeyOf(e: KeyboardEvent): RangeKey | undefined {
55
+ const key = (readingDirection === "rtl" ? RTL_KEYS : LTR_KEYS)[e.key];
56
+ if (!key) return undefined;
57
+ return (e.shiftKey && SHIFTED[key]) || key;
58
+ }
59
+
60
+ export interface RangeOptions {
61
+ values: Accessor<number[] | undefined>;
62
+ defaultValues: Accessor<number[]>;
63
+ min: Accessor<number>;
64
+ max: Accessor<number>;
65
+ step: Accessor<number>;
66
+ minStepsBetween?: Accessor<number>;
67
+ disabled: Accessor<boolean>;
68
+ onChange?: (values: number[]) => void;
69
+ onChangeEnd?: (values: number[]) => void;
70
+ }
71
+
72
+ export interface Range {
73
+ values: Accessor<number[]>;
74
+ fraction: (value: number) => number;
75
+ valueAt: (fraction: number) => number;
76
+ setThumb: (index: number, value: number) => void;
77
+ closestThumb: (value: number) => number;
78
+ keyDown: (e: KeyboardEvent, index: number) => void;
79
+ blur: () => void;
80
+ dragEnd: () => void;
81
+ }
82
+
83
+ const sameValues = (a: number[], b: number[]) =>
84
+ a.length === b.length && a.every((v, i) => v === b[i]);
85
+
86
+ /** Thumbs on a stepped linear track that never cross; a key change ends on blur, a drag on release. */
87
+ export function createRange(options: RangeOptions): Range {
88
+ const [values, setValues] = createControllableSignal({
89
+ value: options.values,
90
+ defaultValue: options.defaultValues,
91
+ onChange: (next) => options.onChange?.(next),
92
+ equals: sameValues,
93
+ });
94
+ const gap = () => (options.minStepsBetween?.() ?? 0) * options.step();
95
+ const pageSize = createMemo(() => pageSizeOf(options.min(), options.max(), options.step()));
96
+ let keyed = false;
97
+
98
+ const bounds = (index: number): [number, number] => {
99
+ const all = values();
100
+ const below = all[index - 1];
101
+ const above = all[index + 1];
102
+ return [
103
+ below === undefined ? options.min() : below + gap(),
104
+ above === undefined ? options.max() : above - gap(),
105
+ ];
106
+ };
107
+
108
+ const setThumb = (index: number, value: number) => {
109
+ if (options.disabled()) return;
110
+ const [low, high] = bounds(index);
111
+ const next = values().slice();
112
+ next[index] = snapValueToStep(value, low, high, options.step());
113
+ setValues(next);
114
+ };
115
+
116
+ const nudge = (index: number, by: number) => {
117
+ const current = values()[index];
118
+ if (current === undefined) return;
119
+ setThumb(index, snapValueToStep(current + by, options.min(), options.max(), options.step()));
120
+ };
121
+
122
+ const fraction = (value: number) => {
123
+ const span = options.max() - options.min();
124
+ return span === 0 ? 0 : (value - options.min()) / span;
125
+ };
126
+
127
+ const valueAt = (at: number) => {
128
+ const min = options.min();
129
+ const max = options.max();
130
+ const step = options.step();
131
+ const raw = at * (max - min) + min;
132
+ return Math.min(max, Math.max(min, Math.round((raw - min) / step) * step + min));
133
+ };
134
+
135
+ const closestThumb = (value: number) => {
136
+ const distances = values().map((v) => Math.abs(v - value));
137
+ const closest = Math.min(...distances);
138
+ const first = distances.indexOf(closest);
139
+ return value < (values()[first] ?? 0) ? first : distances.lastIndexOf(closest);
140
+ };
141
+
142
+ const ACTIONS: Record<RangeKey, (index: number) => void> = {
143
+ decrease: (i) => nudge(i, -options.step()),
144
+ increase: (i) => nudge(i, options.step()),
145
+ pageDown: (i) => nudge(i, -pageSize()),
146
+ pageUp: (i) => nudge(i, pageSize()),
147
+ first: (i) => setThumb(i, bounds(i)[0]),
148
+ last: (i) => setThumb(i, bounds(i)[1]),
149
+ };
150
+
151
+ const keyDown = (e: KeyboardEvent, index: number) => {
152
+ const key = rangeKeyOf(e);
153
+ if (!key || options.disabled()) return;
154
+ e.preventDefault();
155
+ e.stopPropagation();
156
+ keyed = true;
157
+ ACTIONS[key](index);
158
+ };
159
+
160
+ const blur = () => {
161
+ if (!keyed) return;
162
+ keyed = false;
163
+ options.onChangeEnd?.(values());
164
+ };
165
+
166
+ const dragEnd = () => options.onChangeEnd?.(values());
167
+
168
+ return { values, fraction, valueAt, setThumb, closestThumb, keyDown, blur, dragEnd };
169
+ }
170
+
171
+ export const alongTrack = (e: PointerEvent, rect: DOMRect): number =>
172
+ (readingDirection === "rtl" ? rect.right - e.clientX : e.clientX - rect.left) / rect.width;
173
+
174
+ type Pointer = PointerEvent & { currentTarget: HTMLElement };
175
+
176
+ export interface DragOptions {
177
+ disabled: Accessor<boolean>;
178
+ start: (e: PointerEvent, rect: DOMRect) => void;
179
+ move: (e: PointerEvent, rect: DOMRect) => void;
180
+ end: () => void;
181
+ }
182
+
183
+ /** One primary-pointer drag at a time, captured on the pressed element, its rect read once per drag. */
184
+ export function createDrag(options: DragOptions) {
185
+ let pointer: number | undefined;
186
+ let rect: DOMRect | undefined;
187
+
188
+ const finish = (e: Pointer) => {
189
+ if (e.pointerId !== pointer) return;
190
+ pointer = undefined;
191
+ rect = undefined;
192
+ if (e.currentTarget.hasPointerCapture?.(e.pointerId))
193
+ e.currentTarget.releasePointerCapture(e.pointerId);
194
+ options.end();
195
+ };
196
+
197
+ return {
198
+ onPointerDown: (e: Pointer) => {
199
+ if (options.disabled() || e.button !== 0 || pointer !== undefined) return;
200
+ e.preventDefault();
201
+ pointer = e.pointerId;
202
+ e.currentTarget.setPointerCapture?.(e.pointerId);
203
+ rect = e.currentTarget.getBoundingClientRect();
204
+ options.start(e, rect);
205
+ },
206
+ onPointerMove: (e: Pointer) => {
207
+ if (e.pointerId === pointer && rect) options.move(e, rect);
208
+ },
209
+ onPointerUp: finish,
210
+ onPointerCancel: finish,
211
+ };
212
+ }
@@ -0,0 +1,30 @@
1
+ import { createEffect, type JSX, mergeProps, onCleanup, splitProps, untrack } from "solid-js";
2
+
3
+ export function effect<T>(compute: () => T, apply: (value: T) => (() => void) | void): void {
4
+ createEffect(() => {
5
+ const value = compute();
6
+ const cleanup = untrack(() => apply(value));
7
+ if (cleanup) onCleanup(cleanup);
8
+ });
9
+ }
10
+
11
+ export const merge = mergeProps;
12
+
13
+ export function omit<T extends object, K extends keyof T>(
14
+ props: T,
15
+ ...keys: K[]
16
+ ): { [P in keyof T as Exclude<P, K>]: T[P] } {
17
+ return splitProps(props, keys)[1];
18
+ }
19
+
20
+ /** Solid's handler prop is a union: a plain function, or the bound
21
+ * `[handler, data]` form that calls `handler(data, event)`. A wrapper that
22
+ * only checks for a function silently drops the bound one. */
23
+ export function callEventHandler<T, E extends Event>(
24
+ event: E & { currentTarget: T; target: Element },
25
+ handler: JSX.EventHandlerUnion<T, E> | undefined,
26
+ ): void {
27
+ if (!handler) return;
28
+ if (typeof handler === "function") handler(event);
29
+ else handler[0](handler[1], event);
30
+ }
@@ -1,3 +1,4 @@
1
+ import { activeOf, focusWithoutTracking } from "./behavior/focus-scope.js";
1
2
  /** The one door to the clipboard. Call it from the click: browsers refuse a
2
3
  * copy more than a few seconds after it. Text still loading goes in as a
3
4
  * promise so a ClipboardItem write keeps the gesture (Safari). */
@@ -65,17 +66,16 @@ function copyViaSelection(text: string): boolean {
65
66
  // copied nothing.
66
67
  (previous?.parentElement ?? document.body).append(area);
67
68
  try {
68
- area.focus();
69
+ focusWithoutTracking(area);
69
70
  area.select();
70
71
  area.setSelectionRange(0, text.length);
71
- const root = area.getRootNode() as Document | ShadowRoot;
72
- if (root.activeElement !== area) return false;
72
+ if (activeOf(area) !== area) return false;
73
73
  return document.execCommand("copy");
74
74
  } catch {
75
75
  return false;
76
76
  } finally {
77
77
  area.remove();
78
- previous?.focus();
78
+ focusWithoutTracking(previous);
79
79
  }
80
80
  }
81
81