@glasshome/ui 1.42.0 → 1.44.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.
- package/SPEC.md +8 -5
- package/dist/index.js +2 -2
- package/dist/lib/anchor-placement.d.ts +4 -0
- package/dist/lib/balance-rows.d.ts +10 -4
- package/dist/lib/behavior/anchored.d.ts +16 -3
- package/dist/lib/behavior/button-root.d.ts +7 -0
- package/dist/lib/behavior/collection.d.ts +8 -0
- package/dist/lib/behavior/dismiss.d.ts +6 -4
- package/dist/lib/behavior/focus-scope.d.ts +9 -1
- package/dist/lib/behavior/hide-outside.d.ts +1 -1
- package/dist/lib/behavior/layer-stack.d.ts +3 -2
- package/dist/lib/behavior/menu.d.ts +62 -0
- package/dist/lib/behavior/modal-root.d.ts +2 -0
- package/dist/lib/behavior/range.d.ts +44 -0
- package/dist/lib/color/color.d.ts +41 -0
- package/dist/lib/color/index.d.ts +2 -0
- package/dist/lib/color/intl.d.ts +40 -0
- package/dist/lib/dock-slot-classes.d.ts +2 -0
- package/dist/lib/hold.d.ts +1 -1
- package/dist/lib/locale.d.ts +3 -0
- package/dist/lib/menu-classes.d.ts +2 -0
- package/dist/lib/motion-classes.d.ts +2 -1
- package/dist/lib/overlay-classes.d.ts +1 -0
- package/dist/lib/scroll-track.d.ts +3 -2
- package/dist/lib/section-tokens.d.ts +1 -1
- package/dist/lib/segment-classes.d.ts +2 -0
- package/dist/lib/shadow-layer.d.ts +0 -45
- package/dist/lib/toggle-set.d.ts +44 -0
- package/dist/lib/visually-hidden.d.ts +3 -0
- package/dist/solid/accordion.d.ts +35 -11
- package/dist/solid/avatar.d.ts +8 -4
- package/dist/solid/bottom-sheet/bottom-sheet.d.ts +1 -1
- package/dist/solid/button.d.ts +5 -4
- package/dist/solid/charts.d.ts +1 -1
- package/dist/solid/checkbox.d.ts +14 -4
- package/dist/solid/collapsible.d.ts +33 -5
- package/dist/solid/color-disc.d.ts +1 -1
- package/dist/solid/color-slider.d.ts +1 -1
- package/dist/solid/color-wheel.d.ts +1 -1
- package/dist/solid/context-menu.d.ts +58 -24
- package/dist/solid/data-table.d.ts +4 -2
- package/dist/solid/dialog-parts.d.ts +8 -8
- package/dist/solid/dropdown-menu.d.ts +55 -24
- package/dist/solid/empty.d.ts +1 -1
- package/dist/solid/form.d.ts +5 -6
- package/dist/solid/hover-card.d.ts +65 -9
- package/dist/solid/index.d.ts +1 -1
- package/dist/solid/index.js +7752 -13493
- package/dist/solid/input-group.d.ts +6 -6
- package/dist/solid/item.d.ts +1 -1
- package/dist/solid/menu-parts.d.ts +175 -24
- package/dist/solid/option-card.d.ts +1 -4
- package/dist/solid/picker-row.d.ts +2 -0
- package/dist/solid/popover.d.ts +77 -12
- package/dist/solid/progress.d.ts +11 -3
- package/dist/solid/radio-group.d.ts +31 -6
- package/dist/solid/responsive-dialog.d.ts +1 -1
- package/dist/solid/scroll-area.d.ts +1 -1
- package/dist/solid/section-card.d.ts +2 -3
- package/dist/solid/select.d.ts +107 -10
- package/dist/solid/selection.d.ts +10 -1
- package/dist/solid/sheet.d.ts +1 -1
- package/dist/solid/sliding-indicator.d.ts +1 -1
- package/dist/solid/sonner.d.ts +1 -1
- package/dist/solid/toggle.d.ts +11 -3
- package/dist/solid/tooltip.d.ts +22 -22
- package/dist/tokens/index.js +54 -51
- package/dist/{utils-CxAii-e9.js → utils-BbIeGt7o.js} +376 -314
- package/package.json +3 -6
- package/src/lib/anchor-placement.ts +10 -3
- package/src/lib/balance-rows.ts +115 -40
- package/src/lib/behavior/anchored.ts +41 -9
- package/src/lib/behavior/button-root.tsx +103 -0
- package/src/lib/behavior/collection.ts +56 -28
- package/src/lib/behavior/dismiss.ts +61 -21
- package/src/lib/behavior/focus-scope.ts +75 -9
- package/src/lib/behavior/hide-outside.ts +2 -2
- package/src/lib/behavior/layer-stack.ts +33 -8
- package/src/lib/behavior/menu.ts +462 -0
- package/src/lib/behavior/modal-root.tsx +24 -18
- package/src/lib/behavior/polymorphic.tsx +1 -1
- package/src/lib/behavior/presence.ts +1 -1
- package/src/lib/behavior/range.ts +212 -0
- package/src/lib/clipboard.ts +2 -3
- package/src/lib/color/color.ts +746 -0
- package/src/lib/color/index.ts +2 -0
- package/src/lib/color/intl.ts +60 -0
- package/src/lib/dock-slot-classes.ts +3 -0
- package/src/lib/hold.ts +1 -1
- package/src/lib/locale.ts +62 -0
- package/src/lib/menu-classes.ts +3 -0
- package/src/lib/motion-classes.ts +8 -9
- package/src/lib/overlay-classes.ts +1 -3
- package/src/lib/scroll-track.ts +11 -6
- package/src/lib/section-tokens.ts +1 -1
- package/src/lib/segment-classes.ts +3 -0
- package/src/lib/shadow-layer.ts +0 -118
- package/src/lib/toggle-set.ts +133 -0
- package/src/lib/visually-hidden.ts +15 -0
- package/src/solid/accordion.tsx +294 -20
- package/src/solid/area-picker.tsx +4 -4
- package/src/solid/avatar.tsx +98 -24
- package/src/solid/bottom-sheet/arbitration.ts +4 -11
- package/src/solid/bottom-sheet/bottom-sheet.tsx +4 -5
- package/src/solid/bottom-sheet/drag-controller.ts +7 -20
- package/src/solid/button.tsx +12 -6
- package/src/solid/charts.tsx +1 -1
- package/src/solid/checkbox.tsx +167 -44
- package/src/solid/collapsible.tsx +260 -12
- package/src/solid/color-disc.tsx +11 -12
- package/src/solid/color-slider.tsx +114 -47
- package/src/solid/color-wheel.tsx +137 -39
- package/src/solid/context-menu.tsx +285 -94
- package/src/solid/data-table.tsx +48 -22
- package/src/solid/dialog-parts.tsx +39 -17
- package/src/solid/dock.tsx +44 -43
- package/src/solid/dropdown-menu.tsx +252 -115
- package/src/solid/empty.tsx +1 -1
- package/src/solid/entity-selector.tsx +3 -3
- package/src/solid/face-toggle.tsx +43 -18
- package/src/solid/form.tsx +5 -6
- package/src/solid/glyph-tile.tsx +48 -21
- package/src/solid/hover-card.tsx +287 -25
- package/src/solid/icon-picker.tsx +1 -2
- package/src/solid/image-picker.tsx +2 -2
- package/src/solid/index.ts +1 -3
- package/src/solid/input-group.tsx +2 -2
- package/src/solid/item.tsx +1 -1
- package/src/solid/menu-parts.tsx +610 -155
- package/src/solid/option-card.tsx +7 -13
- package/src/solid/picker-row.tsx +5 -1
- package/src/solid/popover.tsx +423 -80
- package/src/solid/preview-tile.tsx +1 -1
- package/src/solid/progress.tsx +84 -15
- package/src/solid/radio-group.tsx +271 -34
- package/src/solid/responsive-dialog.tsx +1 -1
- package/src/solid/schema-form.tsx +1 -6
- package/src/solid/scroll-area.tsx +1 -1
- package/src/solid/section-card.tsx +3 -4
- package/src/solid/select.tsx +939 -95
- package/src/solid/selection.tsx +165 -74
- package/src/solid/sheet.tsx +1 -1
- package/src/solid/slider.tsx +115 -65
- package/src/solid/sliding-indicator.tsx +4 -16
- package/src/solid/sonner.tsx +1 -1
- package/src/solid/tabs.tsx +12 -6
- package/src/solid/term.tsx +3 -4
- package/src/solid/toggle-group.tsx +34 -101
- package/src/solid/toggle.tsx +43 -9
- package/src/solid/tooltip.tsx +24 -24
- package/src/styles/globals.css +61 -50
- package/src/styles/theme.css +12 -6
- package/src/tokens/material.ts +11 -2
|
@@ -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
|
+
}
|
package/src/lib/clipboard.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { focusWithoutTracking } from "./behavior/focus-scope.js";
|
|
1
|
+
import { focusedIn, focusWithoutTracking } from "./behavior/focus-scope.js";
|
|
2
2
|
/** The one door to the clipboard. Call it from the click: browsers refuse a
|
|
3
3
|
* copy more than a few seconds after it. Text still loading goes in as a
|
|
4
4
|
* promise so a ClipboardItem write keeps the gesture (Safari). */
|
|
@@ -69,8 +69,7 @@ function copyViaSelection(text: string): boolean {
|
|
|
69
69
|
focusWithoutTracking(area);
|
|
70
70
|
area.select();
|
|
71
71
|
area.setSelectionRange(0, text.length);
|
|
72
|
-
|
|
73
|
-
if (root.activeElement !== area) return false;
|
|
72
|
+
if (focusedIn(area) !== area) return false;
|
|
74
73
|
return document.execCommand("copy");
|
|
75
74
|
} catch {
|
|
76
75
|
return false;
|