@nesso-how/ui 0.0.0-stage → 1.0.0-alpha.30
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/LICENSE +21 -0
- package/README.md +52 -2
- package/dist/index.d.ts +273 -0
- package/dist/index.js +1088 -0
- package/dist/styles.css +211 -0
- package/package.json +41 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,1088 @@
|
|
|
1
|
+
import { Button as Button$1 } from "@base-ui/react/button";
|
|
2
|
+
import { cva } from "class-variance-authority";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
6
|
+
import { ArrowRight, BookOpen, Check, ChevronDown, ChevronLeft, ChevronRight, CircleHelp, ClipboardPaste, Copy, Download, FileDown, FileUp, Folder, Globe, Info, Layers, Minus, Pencil, Play, Plus, RefreshCw, RotateCcw, Scissors, Search, Share2, Sparkles, TriangleAlert, Upload, X, Zap } from "lucide-react";
|
|
7
|
+
import { Input as Input$1 } from "@base-ui/react/input";
|
|
8
|
+
import { Dialog, Dialog as Dialog$1 } from "@base-ui/react/dialog";
|
|
9
|
+
import { Combobox } from "@base-ui/react/combobox";
|
|
10
|
+
import { Menu } from "@base-ui/react/menu";
|
|
11
|
+
import { Popover } from "@base-ui/react/popover";
|
|
12
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
13
|
+
import { Collapsible } from "@base-ui/react/collapsible";
|
|
14
|
+
import { Tabs } from "@base-ui/react/tabs";
|
|
15
|
+
//#region src/button.tsx
|
|
16
|
+
const buttonVariants = cva("nesso-button inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap border border-transparent px-2.5 font-normal select-none disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-3.5 [&_svg]:shrink-0", {
|
|
17
|
+
variants: {
|
|
18
|
+
variant: {
|
|
19
|
+
default: "bg-primary text-primary-foreground hover:bg-primary-hover active:bg-primary-hover",
|
|
20
|
+
outline: "border-border bg-background hover:bg-accent active:bg-pressed",
|
|
21
|
+
ghost: "hover:bg-accent active:bg-pressed"
|
|
22
|
+
},
|
|
23
|
+
size: {
|
|
24
|
+
default: "min-h-9",
|
|
25
|
+
sm: "min-h-7",
|
|
26
|
+
icon: "size-9 p-0",
|
|
27
|
+
"icon-sm": "size-7 p-0"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
defaultVariants: {
|
|
31
|
+
variant: "default",
|
|
32
|
+
size: "default"
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
function Button({ className, variant = "default", size = "default", ...props }) {
|
|
36
|
+
return /* @__PURE__ */ jsx(Button$1, {
|
|
37
|
+
"data-slot": "button",
|
|
38
|
+
className: cn(buttonVariants({
|
|
39
|
+
variant,
|
|
40
|
+
size,
|
|
41
|
+
className
|
|
42
|
+
})),
|
|
43
|
+
...props
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function IconButton({ className, ...props }) {
|
|
47
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
48
|
+
variant: "ghost",
|
|
49
|
+
size: "icon-sm",
|
|
50
|
+
className: cn("text-muted-foreground hover:bg-transparent hover:text-foreground active:bg-transparent", className),
|
|
51
|
+
...props
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/panel-toggle.tsx
|
|
56
|
+
function PanelToggle({ side, open, className, ...props }) {
|
|
57
|
+
const Icon = side === "left" === open ? ChevronLeft : ChevronRight;
|
|
58
|
+
return /* @__PURE__ */ jsx("button", {
|
|
59
|
+
type: "button",
|
|
60
|
+
className: cn("panel-toggle", className),
|
|
61
|
+
"data-side": side,
|
|
62
|
+
"aria-expanded": open,
|
|
63
|
+
...props,
|
|
64
|
+
children: /* @__PURE__ */ jsx(Icon, { "aria-hidden": "true" })
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/side-panel.tsx
|
|
69
|
+
function SidePanel({ id, side, open, size, minSize, maxSize, onToggle, onSizeChange, toggleLabel, resizeLabel, className, children }) {
|
|
70
|
+
const root = useRef(null);
|
|
71
|
+
const drag = useRef(null);
|
|
72
|
+
const [available, setAvailable] = useState(null);
|
|
73
|
+
const [dragSize, setDragSize] = useState(null);
|
|
74
|
+
const direction = side === "left" ? 1 : -1;
|
|
75
|
+
const limit = typeof maxSize === "number" ? maxSize : available === null ? size : available * parseFloat(maxSize) / 100;
|
|
76
|
+
const maximum = Math.max(minSize, Math.min(limit, available ?? limit));
|
|
77
|
+
const clamp = (value) => Math.min(maximum, Math.max(minSize, value));
|
|
78
|
+
const currentSize = clamp(dragSize ?? size);
|
|
79
|
+
useLayoutEffect(() => {
|
|
80
|
+
const parent = root.current?.parentElement;
|
|
81
|
+
if (!parent) return;
|
|
82
|
+
const measure = () => setAvailable(parent.clientWidth);
|
|
83
|
+
measure();
|
|
84
|
+
const observer = new ResizeObserver(measure);
|
|
85
|
+
observer.observe(parent);
|
|
86
|
+
return () => observer.disconnect();
|
|
87
|
+
}, []);
|
|
88
|
+
const pointerSize = (event) => {
|
|
89
|
+
const start = drag.current;
|
|
90
|
+
if (!start || start.pointerId !== event.pointerId) return null;
|
|
91
|
+
return clamp(start.size + (event.clientX - start.position) * direction);
|
|
92
|
+
};
|
|
93
|
+
const resizeWithKeyboard = (event) => {
|
|
94
|
+
const keys = ["ArrowLeft", "ArrowRight"];
|
|
95
|
+
if (event.key === "Home") onSizeChange(minSize);
|
|
96
|
+
else if (event.key === "End") onSizeChange(maximum);
|
|
97
|
+
else if (keys.includes(event.key)) onSizeChange(clamp(currentSize + (event.key === keys[1] ? 10 : -10) * direction));
|
|
98
|
+
else return;
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
};
|
|
101
|
+
const cancelResize = () => {
|
|
102
|
+
drag.current = null;
|
|
103
|
+
setDragSize(null);
|
|
104
|
+
};
|
|
105
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
106
|
+
ref: root,
|
|
107
|
+
className: cn("side-panel", className),
|
|
108
|
+
"data-side": side,
|
|
109
|
+
"data-open": open,
|
|
110
|
+
"data-resizing": dragSize !== null || void 0,
|
|
111
|
+
style: { "--panel-size": `${currentSize}px` },
|
|
112
|
+
children: [
|
|
113
|
+
/* @__PURE__ */ jsx("div", {
|
|
114
|
+
id,
|
|
115
|
+
className: "side-panel-content",
|
|
116
|
+
inert: !open,
|
|
117
|
+
"aria-hidden": !open,
|
|
118
|
+
children
|
|
119
|
+
}),
|
|
120
|
+
/* @__PURE__ */ jsx("div", {
|
|
121
|
+
className: "side-panel-resize",
|
|
122
|
+
role: "separator",
|
|
123
|
+
tabIndex: open ? 0 : -1,
|
|
124
|
+
"aria-label": resizeLabel,
|
|
125
|
+
"aria-controls": id,
|
|
126
|
+
"aria-orientation": "vertical",
|
|
127
|
+
"aria-valuemin": minSize,
|
|
128
|
+
"aria-valuemax": maximum,
|
|
129
|
+
"aria-valuenow": currentSize,
|
|
130
|
+
onKeyDown: resizeWithKeyboard,
|
|
131
|
+
onPointerDown: (event) => {
|
|
132
|
+
if (event.button !== 0 || drag.current) return;
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
135
|
+
drag.current = {
|
|
136
|
+
pointerId: event.pointerId,
|
|
137
|
+
position: event.clientX,
|
|
138
|
+
size: currentSize
|
|
139
|
+
};
|
|
140
|
+
setDragSize(currentSize);
|
|
141
|
+
},
|
|
142
|
+
onPointerMove: (event) => {
|
|
143
|
+
const next = pointerSize(event);
|
|
144
|
+
if (next !== null) setDragSize(next);
|
|
145
|
+
},
|
|
146
|
+
onPointerUp: (event) => {
|
|
147
|
+
const next = pointerSize(event);
|
|
148
|
+
if (next === null) return;
|
|
149
|
+
cancelResize();
|
|
150
|
+
onSizeChange(next);
|
|
151
|
+
},
|
|
152
|
+
onPointerCancel: cancelResize,
|
|
153
|
+
onLostPointerCapture: cancelResize
|
|
154
|
+
}),
|
|
155
|
+
/* @__PURE__ */ jsx(PanelToggle, {
|
|
156
|
+
side,
|
|
157
|
+
open,
|
|
158
|
+
"aria-label": toggleLabel,
|
|
159
|
+
"aria-controls": id,
|
|
160
|
+
title: toggleLabel,
|
|
161
|
+
onClick: onToggle
|
|
162
|
+
})
|
|
163
|
+
]
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/panel-header.tsx
|
|
168
|
+
function PanelHeader({ actions, className, children, ...props }) {
|
|
169
|
+
return /* @__PURE__ */ jsxs("header", {
|
|
170
|
+
className: cn("nesso-panel-header", className),
|
|
171
|
+
...props,
|
|
172
|
+
children: [children, /* @__PURE__ */ jsx("div", {
|
|
173
|
+
className: "nesso-panel-actions",
|
|
174
|
+
children: actions
|
|
175
|
+
})]
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/spinner.tsx
|
|
180
|
+
function Spinner({ label, className }) {
|
|
181
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
182
|
+
className: cn("flex items-center justify-center text-muted-foreground", className),
|
|
183
|
+
role: "status",
|
|
184
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
185
|
+
className: "nesso-spinner",
|
|
186
|
+
"aria-hidden": "true",
|
|
187
|
+
children: [
|
|
188
|
+
/* @__PURE__ */ jsx("span", {}),
|
|
189
|
+
/* @__PURE__ */ jsx("span", {}),
|
|
190
|
+
/* @__PURE__ */ jsx("span", {}),
|
|
191
|
+
/* @__PURE__ */ jsx("span", {})
|
|
192
|
+
]
|
|
193
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
194
|
+
className: "sr-only",
|
|
195
|
+
children: label
|
|
196
|
+
})]
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/media.ts
|
|
201
|
+
function useMediaQuery(query) {
|
|
202
|
+
return useSyncExternalStore((notify) => {
|
|
203
|
+
const list = window.matchMedia(query);
|
|
204
|
+
list.addEventListener("change", notify);
|
|
205
|
+
return () => list.removeEventListener("change", notify);
|
|
206
|
+
}, () => window.matchMedia(query).matches);
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/input.tsx
|
|
210
|
+
function Input({ className, type, ...props }) {
|
|
211
|
+
return /* @__PURE__ */ jsx(Input$1, {
|
|
212
|
+
type,
|
|
213
|
+
"data-slot": "input",
|
|
214
|
+
className: cn("nesso-input h-9 w-full min-w-0 border border-input bg-background px-2.5 py-1 placeholder:text-muted-foreground focus-visible:border-muted-foreground disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-foreground", className),
|
|
215
|
+
...props
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/label.tsx
|
|
220
|
+
function Label({ className, ...props }) {
|
|
221
|
+
return /* @__PURE__ */ jsx("label", {
|
|
222
|
+
"data-slot": "label",
|
|
223
|
+
className: cn("flex items-center gap-2 text-xs leading-4 text-muted-foreground select-none peer-disabled:opacity-50", className),
|
|
224
|
+
...props
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/kbd.tsx
|
|
229
|
+
function Kbd({ className, ...props }) {
|
|
230
|
+
return /* @__PURE__ */ jsx("kbd", {
|
|
231
|
+
className: cn("inline-flex h-6 min-w-6 items-center justify-center rounded-sm border border-border bg-canvas px-1.5 font-mono text-[11px] leading-none text-muted-foreground", className),
|
|
232
|
+
...props
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/context-label.tsx
|
|
237
|
+
function ContextLabel({ className, ...props }) {
|
|
238
|
+
return /* @__PURE__ */ jsx("p", {
|
|
239
|
+
className: cn("font-mono text-[11px] leading-4 text-muted-foreground", className),
|
|
240
|
+
...props
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/banner.tsx
|
|
245
|
+
function Banner({ tone = "info", className, children, ...props }) {
|
|
246
|
+
return /* @__PURE__ */ jsx("div", {
|
|
247
|
+
"data-slot": "banner",
|
|
248
|
+
"data-tone": tone,
|
|
249
|
+
role: tone === "info" ? "status" : "alert",
|
|
250
|
+
"aria-atomic": "true",
|
|
251
|
+
className: cn("rounded-sm border border-border bg-background px-3 py-2 text-xs leading-5 text-foreground", tone === "warning" && "border-node-border", tone === "error" && "border-foreground", className),
|
|
252
|
+
...props,
|
|
253
|
+
children
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/toast.tsx
|
|
258
|
+
function useToastLifecycle({ id, duration, onDismiss, onRestoreFocus }) {
|
|
259
|
+
const card = useRef(null);
|
|
260
|
+
const remaining = useRef(duration);
|
|
261
|
+
const [hovered, setHovered] = useState(false);
|
|
262
|
+
const [focused, setFocused] = useState(false);
|
|
263
|
+
const [hidden, setHidden] = useState(() => document.hidden);
|
|
264
|
+
const [leaving, setLeaving] = useState(false);
|
|
265
|
+
const paused = hovered || focused || hidden;
|
|
266
|
+
const dismiss = useCallback(() => setLeaving(true), []);
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
const update = () => setHidden(document.hidden);
|
|
269
|
+
document.addEventListener("visibilitychange", update);
|
|
270
|
+
return () => document.removeEventListener("visibilitychange", update);
|
|
271
|
+
}, []);
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
if (!duration || paused || leaving) return;
|
|
274
|
+
const started = performance.now();
|
|
275
|
+
const timer = window.setTimeout(dismiss, remaining.current);
|
|
276
|
+
return () => {
|
|
277
|
+
window.clearTimeout(timer);
|
|
278
|
+
remaining.current = Math.max(0, remaining.current - (performance.now() - started));
|
|
279
|
+
};
|
|
280
|
+
}, [
|
|
281
|
+
duration,
|
|
282
|
+
paused,
|
|
283
|
+
leaving,
|
|
284
|
+
dismiss
|
|
285
|
+
]);
|
|
286
|
+
useEffect(() => {
|
|
287
|
+
if (!leaving) return;
|
|
288
|
+
const timer = window.setTimeout(() => {
|
|
289
|
+
if (card.current?.contains(document.activeElement)) onRestoreFocus();
|
|
290
|
+
onDismiss(id);
|
|
291
|
+
}, window.matchMedia("(prefers-reduced-motion: reduce)").matches ? 0 : 140);
|
|
292
|
+
return () => window.clearTimeout(timer);
|
|
293
|
+
}, [
|
|
294
|
+
leaving,
|
|
295
|
+
id,
|
|
296
|
+
onDismiss,
|
|
297
|
+
onRestoreFocus
|
|
298
|
+
]);
|
|
299
|
+
return {
|
|
300
|
+
card,
|
|
301
|
+
setHovered,
|
|
302
|
+
setFocused,
|
|
303
|
+
paused,
|
|
304
|
+
leaving,
|
|
305
|
+
dismiss
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
const toastIcons = {
|
|
309
|
+
info: Info,
|
|
310
|
+
warning: TriangleAlert,
|
|
311
|
+
confirmation: CircleHelp
|
|
312
|
+
};
|
|
313
|
+
function ToastCard({ item, closeLabel, onDismiss, onRestoreFocus }) {
|
|
314
|
+
const duration = item.tone === "info" ? item.duration ?? 6e3 : 0;
|
|
315
|
+
const { card, setHovered, setFocused, paused, leaving, dismiss } = useToastLifecycle({
|
|
316
|
+
id: item.id,
|
|
317
|
+
duration,
|
|
318
|
+
onDismiss,
|
|
319
|
+
onRestoreFocus
|
|
320
|
+
});
|
|
321
|
+
const Icon = toastIcons[item.tone];
|
|
322
|
+
const act = (action) => {
|
|
323
|
+
if (leaving) return;
|
|
324
|
+
action.onClick();
|
|
325
|
+
dismiss();
|
|
326
|
+
};
|
|
327
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
328
|
+
ref: card,
|
|
329
|
+
"data-slot": "toast",
|
|
330
|
+
"data-tone": item.tone,
|
|
331
|
+
"data-leaving": leaving || void 0,
|
|
332
|
+
className: "nesso-toast",
|
|
333
|
+
onMouseEnter: () => setHovered(true),
|
|
334
|
+
onMouseLeave: () => setHovered(false),
|
|
335
|
+
onFocusCapture: () => setFocused(true),
|
|
336
|
+
onBlurCapture: (event) => {
|
|
337
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);
|
|
338
|
+
},
|
|
339
|
+
children: [
|
|
340
|
+
/* @__PURE__ */ jsxs("p", {
|
|
341
|
+
className: "sr-only",
|
|
342
|
+
role: item.tone === "warning" ? "alert" : "status",
|
|
343
|
+
"aria-atomic": "true",
|
|
344
|
+
children: [
|
|
345
|
+
item.label,
|
|
346
|
+
": ",
|
|
347
|
+
item.title,
|
|
348
|
+
". ",
|
|
349
|
+
item.description
|
|
350
|
+
]
|
|
351
|
+
}),
|
|
352
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
353
|
+
className: "toast-icon",
|
|
354
|
+
"aria-hidden": "true"
|
|
355
|
+
}),
|
|
356
|
+
/* @__PURE__ */ jsxs("div", {
|
|
357
|
+
className: "toast-content",
|
|
358
|
+
children: [
|
|
359
|
+
/* @__PURE__ */ jsx("span", {
|
|
360
|
+
className: "toast-label",
|
|
361
|
+
children: item.label
|
|
362
|
+
}),
|
|
363
|
+
/* @__PURE__ */ jsx("h2", {
|
|
364
|
+
className: "toast-title",
|
|
365
|
+
children: item.title
|
|
366
|
+
}),
|
|
367
|
+
item.description && /* @__PURE__ */ jsx("p", {
|
|
368
|
+
className: "toast-description",
|
|
369
|
+
children: item.description
|
|
370
|
+
})
|
|
371
|
+
]
|
|
372
|
+
}),
|
|
373
|
+
item.tone !== "confirmation" && /* @__PURE__ */ jsx(Button, {
|
|
374
|
+
variant: "ghost",
|
|
375
|
+
size: "icon-sm",
|
|
376
|
+
className: "toast-close",
|
|
377
|
+
"aria-label": `${closeLabel}: ${item.title}`,
|
|
378
|
+
disabled: leaving,
|
|
379
|
+
onClick: dismiss,
|
|
380
|
+
children: /* @__PURE__ */ jsx(X, {})
|
|
381
|
+
}),
|
|
382
|
+
item.action && /* @__PURE__ */ jsxs("div", {
|
|
383
|
+
className: "toast-actions",
|
|
384
|
+
children: [item.tone === "confirmation" && /* @__PURE__ */ jsx(Button, {
|
|
385
|
+
size: "sm",
|
|
386
|
+
variant: "ghost",
|
|
387
|
+
disabled: leaving,
|
|
388
|
+
onClick: () => act(item.cancelAction),
|
|
389
|
+
children: item.cancelAction.label
|
|
390
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
391
|
+
size: "sm",
|
|
392
|
+
variant: item.tone === "confirmation" ? "default" : "outline",
|
|
393
|
+
disabled: leaving,
|
|
394
|
+
onClick: () => {
|
|
395
|
+
if (item.action) act(item.action);
|
|
396
|
+
},
|
|
397
|
+
children: item.action.label
|
|
398
|
+
})]
|
|
399
|
+
}),
|
|
400
|
+
duration > 0 && /* @__PURE__ */ jsx("div", {
|
|
401
|
+
"aria-hidden": "true",
|
|
402
|
+
className: "toast-progress",
|
|
403
|
+
style: {
|
|
404
|
+
"--toast-duration": `${duration}ms`,
|
|
405
|
+
animationPlayState: paused || leaving ? "paused" : "running"
|
|
406
|
+
}
|
|
407
|
+
})
|
|
408
|
+
]
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
function ToastViewport({ items, label, closeLabel, queueLabel, onDismiss, onRestoreFocus }) {
|
|
412
|
+
if (items.length === 0) return null;
|
|
413
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
414
|
+
className: "toast-viewport",
|
|
415
|
+
"aria-label": label,
|
|
416
|
+
children: [items.length > 3 && /* @__PURE__ */ jsx("p", {
|
|
417
|
+
className: "toast-queue",
|
|
418
|
+
role: "status",
|
|
419
|
+
children: queueLabel
|
|
420
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
421
|
+
className: "toast-stack",
|
|
422
|
+
children: items.slice(0, 3).map((item) => /* @__PURE__ */ jsx(ToastCard, {
|
|
423
|
+
item,
|
|
424
|
+
closeLabel,
|
|
425
|
+
onDismiss,
|
|
426
|
+
onRestoreFocus
|
|
427
|
+
}, item.id))
|
|
428
|
+
})]
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/dialog.tsx
|
|
433
|
+
function DialogPopup({ className, ...props }) {
|
|
434
|
+
return /* @__PURE__ */ jsxs(Dialog.Portal, { children: [/* @__PURE__ */ jsx(Dialog.Backdrop, {
|
|
435
|
+
forceRender: true,
|
|
436
|
+
className: "fixed inset-0 z-50 bg-foreground/20"
|
|
437
|
+
}), /* @__PURE__ */ jsx(Dialog.Popup, {
|
|
438
|
+
className: cn("nesso-popup fixed top-1/2 left-1/2 z-50 w-[min(400px,calc(100vw-32px))] -translate-1/2 border-0 p-6", className),
|
|
439
|
+
...props
|
|
440
|
+
})] });
|
|
441
|
+
}
|
|
442
|
+
function DialogActions({ className, children }) {
|
|
443
|
+
return /* @__PURE__ */ jsx("div", {
|
|
444
|
+
className: cn("mt-6 flex justify-end gap-2", className),
|
|
445
|
+
children
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
function ConfirmDialog({ open, onOpenChange, title, description, cancelLabel, confirmLabel, onConfirm, initialFocus, finalFocus, children }) {
|
|
449
|
+
const cancel = useRef(null);
|
|
450
|
+
return /* @__PURE__ */ jsx(Dialog.Root, {
|
|
451
|
+
open,
|
|
452
|
+
onOpenChange,
|
|
453
|
+
children: /* @__PURE__ */ jsxs(DialogPopup, {
|
|
454
|
+
initialFocus: initialFocus ?? cancel,
|
|
455
|
+
finalFocus,
|
|
456
|
+
children: [
|
|
457
|
+
/* @__PURE__ */ jsx(Dialog.Title, {
|
|
458
|
+
className: "text-sm",
|
|
459
|
+
children: title
|
|
460
|
+
}),
|
|
461
|
+
/* @__PURE__ */ jsx(Dialog.Description, {
|
|
462
|
+
className: "mt-2 text-xs text-muted-foreground",
|
|
463
|
+
children: description
|
|
464
|
+
}),
|
|
465
|
+
children,
|
|
466
|
+
/* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Dialog.Close, {
|
|
467
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
468
|
+
ref: cancel,
|
|
469
|
+
variant: "outline"
|
|
470
|
+
}),
|
|
471
|
+
children: cancelLabel
|
|
472
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
473
|
+
onClick: onConfirm,
|
|
474
|
+
children: confirmLabel
|
|
475
|
+
})] })
|
|
476
|
+
]
|
|
477
|
+
})
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/prompt.tsx
|
|
482
|
+
function PromptForm({ initialValue = "", nameLabel, submitLabel, cancelLabel, maxLength, onSubmit }) {
|
|
483
|
+
const [value, setValue] = useState(initialValue);
|
|
484
|
+
const id = useId();
|
|
485
|
+
return /* @__PURE__ */ jsxs("form", {
|
|
486
|
+
className: "mt-6",
|
|
487
|
+
onSubmit: (event) => {
|
|
488
|
+
event.preventDefault();
|
|
489
|
+
if (value.trim()) onSubmit(value);
|
|
490
|
+
},
|
|
491
|
+
children: [
|
|
492
|
+
/* @__PURE__ */ jsx(Label, {
|
|
493
|
+
htmlFor: id,
|
|
494
|
+
children: nameLabel
|
|
495
|
+
}),
|
|
496
|
+
/* @__PURE__ */ jsx(Input, {
|
|
497
|
+
id,
|
|
498
|
+
value,
|
|
499
|
+
onChange: (event) => setValue(event.target.value),
|
|
500
|
+
onFocus: (event) => event.target.select(),
|
|
501
|
+
maxLength,
|
|
502
|
+
className: "mt-2"
|
|
503
|
+
}),
|
|
504
|
+
/* @__PURE__ */ jsxs(DialogActions, { children: [/* @__PURE__ */ jsx(Dialog$1.Close, {
|
|
505
|
+
render: /* @__PURE__ */ jsx(Button, { variant: "outline" }),
|
|
506
|
+
children: cancelLabel
|
|
507
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
508
|
+
type: "submit",
|
|
509
|
+
disabled: !value.trim(),
|
|
510
|
+
children: submitLabel
|
|
511
|
+
})] })
|
|
512
|
+
]
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
function TextPromptDialog({ open, onOpenChange, title, description, initialValue, nameLabel, submitLabel, cancelLabel, maxLength, onSubmit, finalFocus, trigger }) {
|
|
516
|
+
return /* @__PURE__ */ jsxs(Dialog$1.Root, {
|
|
517
|
+
open,
|
|
518
|
+
onOpenChange,
|
|
519
|
+
children: [trigger, /* @__PURE__ */ jsxs(DialogPopup, {
|
|
520
|
+
finalFocus,
|
|
521
|
+
children: [
|
|
522
|
+
/* @__PURE__ */ jsx(Dialog$1.Title, {
|
|
523
|
+
className: "text-sm",
|
|
524
|
+
children: title
|
|
525
|
+
}),
|
|
526
|
+
/* @__PURE__ */ jsx(Dialog$1.Description, {
|
|
527
|
+
className: "mt-2 text-xs text-muted-foreground",
|
|
528
|
+
children: description
|
|
529
|
+
}),
|
|
530
|
+
/* @__PURE__ */ jsx(PromptForm, {
|
|
531
|
+
initialValue,
|
|
532
|
+
nameLabel,
|
|
533
|
+
submitLabel,
|
|
534
|
+
cancelLabel,
|
|
535
|
+
maxLength,
|
|
536
|
+
onSubmit
|
|
537
|
+
})
|
|
538
|
+
]
|
|
539
|
+
})]
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
//#endregion
|
|
543
|
+
//#region src/row.tsx
|
|
544
|
+
function ListRow({ className, children }) {
|
|
545
|
+
return /* @__PURE__ */ jsx("div", {
|
|
546
|
+
className: cn("group flex min-h-14 items-center gap-1 rounded-sm hover:bg-accent has-[:focus-visible]:bg-accent", className),
|
|
547
|
+
children
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
function ListRowButton({ className, ...props }) {
|
|
551
|
+
return /* @__PURE__ */ jsx("button", {
|
|
552
|
+
type: "button",
|
|
553
|
+
className: cn("min-w-0 flex-1 rounded-sm px-2.5 py-2 text-left", className),
|
|
554
|
+
...props
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
function ListRowTitle({ active, className, children }) {
|
|
558
|
+
return /* @__PURE__ */ jsx("span", {
|
|
559
|
+
className: cn("block text-[13px] leading-[19px] break-words", active && "font-medium", className),
|
|
560
|
+
children
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
function ListRowDetail({ className, children }) {
|
|
564
|
+
return /* @__PURE__ */ jsx("span", {
|
|
565
|
+
className: cn("mt-[3px] block font-mono text-[10px] leading-[14px] text-muted-foreground", className),
|
|
566
|
+
children
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
function RevealActions({ className, children }) {
|
|
570
|
+
return /* @__PURE__ */ jsx("div", {
|
|
571
|
+
className: cn("flex shrink-0 items-center opacity-0 group-hover:opacity-100 group-has-[:focus-visible]:opacity-100 has-[button[data-popup-open]]:opacity-100 [@media(pointer:coarse)]:opacity-100", className),
|
|
572
|
+
children
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
function Field({ className, children }) {
|
|
576
|
+
return /* @__PURE__ */ jsx("div", {
|
|
577
|
+
className: cn("nesso-field", className),
|
|
578
|
+
children
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
function FieldHint({ className, ...props }) {
|
|
582
|
+
return /* @__PURE__ */ jsx("p", {
|
|
583
|
+
className: cn("nesso-field-hint", className),
|
|
584
|
+
...props
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
//#endregion
|
|
588
|
+
//#region src/combobox.tsx
|
|
589
|
+
function ComboboxPopup({ className, children, ...props }) {
|
|
590
|
+
return /* @__PURE__ */ jsx(Combobox.Portal, { children: /* @__PURE__ */ jsx(Combobox.Positioner, {
|
|
591
|
+
align: "start",
|
|
592
|
+
sideOffset: 4,
|
|
593
|
+
className: "z-50",
|
|
594
|
+
children: /* @__PURE__ */ jsx(Combobox.Popup, {
|
|
595
|
+
className: cn("nesso-popup w-(--anchor-width) p-1", className),
|
|
596
|
+
...props,
|
|
597
|
+
children
|
|
598
|
+
})
|
|
599
|
+
}) });
|
|
600
|
+
}
|
|
601
|
+
function ComboboxItem({ className, ...props }) {
|
|
602
|
+
return /* @__PURE__ */ jsx(Combobox.Item, {
|
|
603
|
+
className: cn("nesso-option cursor-default px-2.5 py-2", className),
|
|
604
|
+
...props
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
//#endregion
|
|
608
|
+
//#region src/preference-select.tsx
|
|
609
|
+
function PreferenceSelect({ label, items, value, onChange, disabled }) {
|
|
610
|
+
const id = useId();
|
|
611
|
+
return /* @__PURE__ */ jsxs(Field, { children: [/* @__PURE__ */ jsx(Label, {
|
|
612
|
+
id: `${id}-label`,
|
|
613
|
+
htmlFor: id,
|
|
614
|
+
className: "w-fit",
|
|
615
|
+
children: label
|
|
616
|
+
}), /* @__PURE__ */ jsxs(Combobox.Root, {
|
|
617
|
+
items,
|
|
618
|
+
value: items.find((item) => item.value === value) ?? null,
|
|
619
|
+
onValueChange: (item) => {
|
|
620
|
+
if (item) onChange(item.value);
|
|
621
|
+
},
|
|
622
|
+
filter: null,
|
|
623
|
+
disabled,
|
|
624
|
+
children: [/* @__PURE__ */ jsxs(Combobox.Trigger, {
|
|
625
|
+
id,
|
|
626
|
+
"aria-labelledby": `${id}-label`,
|
|
627
|
+
render: /* @__PURE__ */ jsx(Button, {
|
|
628
|
+
variant: "outline",
|
|
629
|
+
className: "w-full justify-between"
|
|
630
|
+
}),
|
|
631
|
+
children: [/* @__PURE__ */ jsx(Combobox.Value, {}), /* @__PURE__ */ jsx(ChevronDown, { className: "text-muted-foreground" })]
|
|
632
|
+
}), /* @__PURE__ */ jsx(ComboboxPopup, {
|
|
633
|
+
className: "nesso-field-popup",
|
|
634
|
+
children: /* @__PURE__ */ jsx(Combobox.List, { children: (item) => /* @__PURE__ */ jsxs(ComboboxItem, {
|
|
635
|
+
value: item,
|
|
636
|
+
className: "flex items-center justify-between",
|
|
637
|
+
children: [item.label, /* @__PURE__ */ jsx(Combobox.ItemIndicator, { children: /* @__PURE__ */ jsx(Check, { className: "size-3.5" }) })]
|
|
638
|
+
}, item.value) })
|
|
639
|
+
})]
|
|
640
|
+
})] });
|
|
641
|
+
}
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/menu.tsx
|
|
644
|
+
function MenuPopup({ className, align = "start", anchor, sideOffset = 4, children, ...props }) {
|
|
645
|
+
return /* @__PURE__ */ jsx(Menu.Portal, { children: /* @__PURE__ */ jsx(Menu.Positioner, {
|
|
646
|
+
align,
|
|
647
|
+
anchor,
|
|
648
|
+
sideOffset,
|
|
649
|
+
className: "z-50",
|
|
650
|
+
children: /* @__PURE__ */ jsx(Menu.Popup, {
|
|
651
|
+
className: cn("nesso-popup w-max min-w-32 max-w-[calc(100vw-32px)] max-h-(--available-height) overflow-y-auto p-1", className),
|
|
652
|
+
...props,
|
|
653
|
+
children
|
|
654
|
+
})
|
|
655
|
+
}) });
|
|
656
|
+
}
|
|
657
|
+
function MenuItem({ className, ...props }) {
|
|
658
|
+
return /* @__PURE__ */ jsx(Menu.Item, {
|
|
659
|
+
className: cn("nesso-option flex cursor-default items-center gap-2 px-2.5 py-2 data-disabled:opacity-40 [&_svg]:size-3.5 [&_svg]:shrink-0 [&_svg]:text-muted-foreground", className),
|
|
660
|
+
...props
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
function MenuRadioItem({ className, children, ...props }) {
|
|
664
|
+
return /* @__PURE__ */ jsxs(Menu.RadioItem, {
|
|
665
|
+
className: cn("nesso-option flex cursor-default items-center gap-2 px-2.5 py-2", className),
|
|
666
|
+
...props,
|
|
667
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
668
|
+
className: "size-3.5",
|
|
669
|
+
children: /* @__PURE__ */ jsx(Menu.RadioItemIndicator, { children: /* @__PURE__ */ jsx(Check, { className: "size-3.5" }) })
|
|
670
|
+
}), children]
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
//#endregion
|
|
674
|
+
//#region src/popover.tsx
|
|
675
|
+
function PopoverPopup({ className, anchor, align = "start", sideOffset = 4, children, ...props }) {
|
|
676
|
+
return /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(Popover.Positioner, {
|
|
677
|
+
align,
|
|
678
|
+
anchor,
|
|
679
|
+
sideOffset,
|
|
680
|
+
className: "z-50",
|
|
681
|
+
children: /* @__PURE__ */ jsx(Popover.Popup, {
|
|
682
|
+
className: cn("nesso-popup z-50 max-h-(--available-height) overflow-y-auto p-3 outline-none", className),
|
|
683
|
+
...props,
|
|
684
|
+
children
|
|
685
|
+
})
|
|
686
|
+
}) });
|
|
687
|
+
}
|
|
688
|
+
//#endregion
|
|
689
|
+
//#region src/color.ts
|
|
690
|
+
const colorLuminance = (hex) => {
|
|
691
|
+
const channels = hex.slice(1).match(/.{2}/g).map((value) => parseInt(value, 16) / 255).map((value) => value <= .04045 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4);
|
|
692
|
+
return channels[0] * .2126 + channels[1] * .7152 + channels[2] * .0722;
|
|
693
|
+
};
|
|
694
|
+
const contrastColor = (hex) => {
|
|
695
|
+
const lightness = colorLuminance(hex);
|
|
696
|
+
if ((lightness + .05) / (colorLuminance("#292929") + .05) >= 4.5) return "#292929";
|
|
697
|
+
if (1.05 / (lightness + .05) >= 4.5) return "#ffffff";
|
|
698
|
+
return "#000000";
|
|
699
|
+
};
|
|
700
|
+
const hexToHsv = (hex, previousHue) => {
|
|
701
|
+
const [red, green, blue] = hex.slice(1).match(/.{2}/g).map((value) => parseInt(value, 16) / 255);
|
|
702
|
+
const max = Math.max(red, green, blue);
|
|
703
|
+
const delta = max - Math.min(red, green, blue);
|
|
704
|
+
let hue = previousHue;
|
|
705
|
+
if (delta) {
|
|
706
|
+
if (max === red) hue = 60 * (((green - blue) / delta + 6) % 6);
|
|
707
|
+
else if (max === green) hue = 60 * ((blue - red) / delta + 2);
|
|
708
|
+
else hue = 60 * ((red - green) / delta + 4);
|
|
709
|
+
}
|
|
710
|
+
return {
|
|
711
|
+
h: hue,
|
|
712
|
+
s: max ? delta / max : 0,
|
|
713
|
+
v: max
|
|
714
|
+
};
|
|
715
|
+
};
|
|
716
|
+
const hsvToHex = ({ h, s, v }) => {
|
|
717
|
+
const channel = (offset) => {
|
|
718
|
+
const position = (offset + h / 60) % 6;
|
|
719
|
+
const value = v - v * s * Math.max(0, Math.min(position, 4 - position, 1));
|
|
720
|
+
return Math.round(value * 255).toString(16).padStart(2, "0");
|
|
721
|
+
};
|
|
722
|
+
return `#${channel(5)}${channel(3)}${channel(1)}`;
|
|
723
|
+
};
|
|
724
|
+
const presetColors = [
|
|
725
|
+
{
|
|
726
|
+
key: "presetWhite",
|
|
727
|
+
value: "#ffffff"
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
key: "presetSand",
|
|
731
|
+
value: "#f3ead5"
|
|
732
|
+
},
|
|
733
|
+
{
|
|
734
|
+
key: "presetPeach",
|
|
735
|
+
value: "#f5e3d5"
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
key: "presetRose",
|
|
739
|
+
value: "#f5dfe2"
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
key: "presetSage",
|
|
743
|
+
value: "#e1ecde"
|
|
744
|
+
},
|
|
745
|
+
{
|
|
746
|
+
key: "presetMint",
|
|
747
|
+
value: "#dceee8"
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
key: "presetSky",
|
|
751
|
+
value: "#dfeaf5"
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
key: "presetLavender",
|
|
755
|
+
value: "#e9e2f3"
|
|
756
|
+
}
|
|
757
|
+
];
|
|
758
|
+
//#endregion
|
|
759
|
+
//#region src/color-picker.tsx
|
|
760
|
+
const defaultColor = "#ffffff";
|
|
761
|
+
const clamp = (value) => Math.max(0, Math.min(1, value));
|
|
762
|
+
function ColorPicker({ value: color, onValueChange, onCopyError, labels, presets, disabled = false, inputProps }) {
|
|
763
|
+
const hexId = useId();
|
|
764
|
+
const hint = `${hexId}-hint`;
|
|
765
|
+
const copyTimer = useRef(void 0);
|
|
766
|
+
const colorGroup = useRef(void 0);
|
|
767
|
+
const value = color ?? defaultColor;
|
|
768
|
+
const mixed = color === null;
|
|
769
|
+
const [picker, setPicker] = useState(() => ({
|
|
770
|
+
value,
|
|
771
|
+
hsv: hexToHsv(value, 0)
|
|
772
|
+
}));
|
|
773
|
+
if (picker.value !== value) setPicker({
|
|
774
|
+
value,
|
|
775
|
+
hsv: hexToHsv(value, picker.hsv.h)
|
|
776
|
+
});
|
|
777
|
+
const { hsv } = picker;
|
|
778
|
+
const [open, setOpen] = useState(false);
|
|
779
|
+
const [copiedValue, setCopiedValue] = useState(null);
|
|
780
|
+
const [hexDraft, setHexDraft] = useState(null);
|
|
781
|
+
const copied = copiedValue === value;
|
|
782
|
+
useEffect(() => () => clearTimeout(copyTimer.current), []);
|
|
783
|
+
const apply = (next, interactionId) => {
|
|
784
|
+
const color = hsvToHex(next);
|
|
785
|
+
setPicker({
|
|
786
|
+
value: color,
|
|
787
|
+
hsv: next
|
|
788
|
+
});
|
|
789
|
+
colorGroup.current = interactionId;
|
|
790
|
+
onValueChange(color, interactionId);
|
|
791
|
+
};
|
|
792
|
+
const onAreaPointer = (event) => {
|
|
793
|
+
const target = event.currentTarget;
|
|
794
|
+
if (event.type === "pointerdown") {
|
|
795
|
+
if (event.button !== 0) return;
|
|
796
|
+
event.preventDefault();
|
|
797
|
+
target.focus({ preventScroll: true });
|
|
798
|
+
target.setPointerCapture(event.pointerId);
|
|
799
|
+
colorGroup.current = crypto.randomUUID();
|
|
800
|
+
}
|
|
801
|
+
if (!target.hasPointerCapture(event.pointerId)) return;
|
|
802
|
+
const { left, top, width, height } = target.getBoundingClientRect();
|
|
803
|
+
apply({
|
|
804
|
+
...hsv,
|
|
805
|
+
s: clamp((event.clientX - left) / width),
|
|
806
|
+
v: 1 - clamp((event.clientY - top) / height)
|
|
807
|
+
}, colorGroup.current);
|
|
808
|
+
if (event.type === "pointerup" || event.type === "pointercancel") {
|
|
809
|
+
target.releasePointerCapture(event.pointerId);
|
|
810
|
+
colorGroup.current = void 0;
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
const onAreaKeyDown = (event) => {
|
|
814
|
+
const step = event.shiftKey ? .1 : .01;
|
|
815
|
+
let next;
|
|
816
|
+
if (event.key === "ArrowLeft") next = {
|
|
817
|
+
...hsv,
|
|
818
|
+
s: clamp(hsv.s - step)
|
|
819
|
+
};
|
|
820
|
+
else if (event.key === "ArrowRight") next = {
|
|
821
|
+
...hsv,
|
|
822
|
+
s: clamp(hsv.s + step)
|
|
823
|
+
};
|
|
824
|
+
else if (event.key === "ArrowUp") next = {
|
|
825
|
+
...hsv,
|
|
826
|
+
v: clamp(hsv.v + step)
|
|
827
|
+
};
|
|
828
|
+
else if (event.key === "ArrowDown") next = {
|
|
829
|
+
...hsv,
|
|
830
|
+
v: clamp(hsv.v - step)
|
|
831
|
+
};
|
|
832
|
+
else return;
|
|
833
|
+
event.preventDefault();
|
|
834
|
+
apply(next);
|
|
835
|
+
};
|
|
836
|
+
const changeHex = (raw) => {
|
|
837
|
+
const match = /^#?([0-9a-f]{6})$/i.exec(raw.trim());
|
|
838
|
+
setHexDraft({
|
|
839
|
+
value: raw,
|
|
840
|
+
invalid: !match
|
|
841
|
+
});
|
|
842
|
+
if (match) apply(hexToHsv(`#${match[1]}`, hsv.h));
|
|
843
|
+
};
|
|
844
|
+
const copyValue = async () => {
|
|
845
|
+
try {
|
|
846
|
+
await navigator.clipboard.writeText(value.toUpperCase());
|
|
847
|
+
setCopiedValue(value);
|
|
848
|
+
clearTimeout(copyTimer.current);
|
|
849
|
+
copyTimer.current = window.setTimeout(() => setCopiedValue(null), 2500);
|
|
850
|
+
} catch {
|
|
851
|
+
setCopiedValue(null);
|
|
852
|
+
onCopyError();
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
856
|
+
className: "flex flex-col gap-1.5",
|
|
857
|
+
children: [/* @__PURE__ */ jsx(Label, { children: labels.color }), /* @__PURE__ */ jsxs("div", {
|
|
858
|
+
className: "flex min-h-8 items-center gap-1 rounded-sm border border-input bg-background p-1",
|
|
859
|
+
children: [
|
|
860
|
+
/* @__PURE__ */ jsxs(Popover.Root, {
|
|
861
|
+
open: disabled ? false : open,
|
|
862
|
+
onOpenChange: setOpen,
|
|
863
|
+
children: [/* @__PURE__ */ jsx(Popover.Trigger, {
|
|
864
|
+
render: /* @__PURE__ */ jsx(IconButton, { className: "size-6" }),
|
|
865
|
+
"aria-label": labels.chooseColor,
|
|
866
|
+
disabled,
|
|
867
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
868
|
+
className: "grid size-4 shrink-0 place-items-center rounded-xs border border-node-border bg-muted",
|
|
869
|
+
style: { background: mixed ? void 0 : value },
|
|
870
|
+
"aria-hidden": "true",
|
|
871
|
+
children: mixed && /* @__PURE__ */ jsx(Minus, {})
|
|
872
|
+
})
|
|
873
|
+
}), /* @__PURE__ */ jsxs(PopoverPopup, {
|
|
874
|
+
className: "flex w-58 flex-col gap-3",
|
|
875
|
+
"aria-label": labels.title,
|
|
876
|
+
children: [
|
|
877
|
+
/* @__PURE__ */ jsx("div", {
|
|
878
|
+
tabIndex: 0,
|
|
879
|
+
role: "group",
|
|
880
|
+
"aria-label": labels.saturationBrightness,
|
|
881
|
+
"aria-describedby": hint,
|
|
882
|
+
className: "relative h-32 touch-none rounded-xs cursor-crosshair focus-visible:outline-2 focus-visible:outline-ring focus-visible:-outline-offset-2",
|
|
883
|
+
style: {
|
|
884
|
+
backgroundColor: hsvToHex({
|
|
885
|
+
h: hsv.h,
|
|
886
|
+
s: 1,
|
|
887
|
+
v: 1
|
|
888
|
+
}),
|
|
889
|
+
backgroundImage: "linear-gradient(to top, #000000, transparent), linear-gradient(to right, #ffffff, transparent)"
|
|
890
|
+
},
|
|
891
|
+
onPointerDown: onAreaPointer,
|
|
892
|
+
onPointerMove: onAreaPointer,
|
|
893
|
+
onPointerUp: onAreaPointer,
|
|
894
|
+
onPointerCancel: onAreaPointer,
|
|
895
|
+
onKeyDown: onAreaKeyDown,
|
|
896
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
897
|
+
"aria-hidden": "true",
|
|
898
|
+
className: "pointer-events-none absolute size-2.5 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-[0_0_0_1px_#29292980]",
|
|
899
|
+
style: {
|
|
900
|
+
left: `${hsv.s * 100}%`,
|
|
901
|
+
top: `${(1 - hsv.v) * 100}%`
|
|
902
|
+
}
|
|
903
|
+
})
|
|
904
|
+
}),
|
|
905
|
+
/* @__PURE__ */ jsx("p", {
|
|
906
|
+
id: hint,
|
|
907
|
+
className: "sr-only",
|
|
908
|
+
children: labels.saturationHint
|
|
909
|
+
}),
|
|
910
|
+
/* @__PURE__ */ jsx("input", {
|
|
911
|
+
id: `${hexId}-hue`,
|
|
912
|
+
type: "range",
|
|
913
|
+
min: 0,
|
|
914
|
+
max: 359,
|
|
915
|
+
step: 1,
|
|
916
|
+
value: Math.round(hsv.h) % 360,
|
|
917
|
+
"aria-label": labels.hue,
|
|
918
|
+
className: "nesso-color-hue h-5 w-full cursor-pointer focus-visible:rounded-xs focus-visible:outline-2 focus-visible:outline-ring focus-visible:-outline-offset-2",
|
|
919
|
+
onBlur: () => {
|
|
920
|
+
colorGroup.current = void 0;
|
|
921
|
+
},
|
|
922
|
+
onPointerDown: () => {
|
|
923
|
+
colorGroup.current = crypto.randomUUID();
|
|
924
|
+
},
|
|
925
|
+
onPointerUp: () => {
|
|
926
|
+
colorGroup.current = void 0;
|
|
927
|
+
},
|
|
928
|
+
onPointerCancel: () => {
|
|
929
|
+
colorGroup.current = void 0;
|
|
930
|
+
},
|
|
931
|
+
onChange: (event) => apply({
|
|
932
|
+
...hsv,
|
|
933
|
+
h: Number(event.target.value)
|
|
934
|
+
}, colorGroup.current ??= crypto.randomUUID())
|
|
935
|
+
}),
|
|
936
|
+
/* @__PURE__ */ jsx("div", {
|
|
937
|
+
role: "group",
|
|
938
|
+
"aria-label": labels.colorPresets,
|
|
939
|
+
className: "flex justify-between",
|
|
940
|
+
children: presets.map((preset) => /* @__PURE__ */ jsx(IconButton, {
|
|
941
|
+
title: preset.label,
|
|
942
|
+
"aria-label": preset.label,
|
|
943
|
+
"aria-pressed": !mixed && preset.value === value,
|
|
944
|
+
onClick: () => apply(hexToHsv(preset.value, hsv.h)),
|
|
945
|
+
className: "size-6 [&_svg]:size-3",
|
|
946
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
947
|
+
className: "grid size-4 place-items-center rounded-xs border border-black/10",
|
|
948
|
+
style: { background: preset.value },
|
|
949
|
+
"aria-hidden": "true",
|
|
950
|
+
children: !mixed && preset.value === value && /* @__PURE__ */ jsx(Check, {
|
|
951
|
+
className: "text-foreground",
|
|
952
|
+
"aria-hidden": "true"
|
|
953
|
+
})
|
|
954
|
+
})
|
|
955
|
+
}, preset.value))
|
|
956
|
+
}),
|
|
957
|
+
/* @__PURE__ */ jsxs("div", {
|
|
958
|
+
className: "flex items-center gap-2",
|
|
959
|
+
children: [/* @__PURE__ */ jsx(Label, {
|
|
960
|
+
htmlFor: hexId,
|
|
961
|
+
className: "shrink-0",
|
|
962
|
+
children: labels.hex
|
|
963
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
964
|
+
className: "relative min-w-0 flex-1",
|
|
965
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
966
|
+
...inputProps,
|
|
967
|
+
id: hexId,
|
|
968
|
+
value: hexDraft?.value ?? (mixed ? "" : value.toUpperCase()),
|
|
969
|
+
placeholder: mixed ? labels.mixed : void 0,
|
|
970
|
+
maxLength: 7,
|
|
971
|
+
autoComplete: "off",
|
|
972
|
+
spellCheck: false,
|
|
973
|
+
"aria-invalid": hexDraft?.invalid ?? false,
|
|
974
|
+
"aria-describedby": `${hexId}-error`,
|
|
975
|
+
className: "h-7 pr-8 font-mono text-[11px]",
|
|
976
|
+
onChange: (event) => changeHex(event.target.value),
|
|
977
|
+
onBlur: () => setHexDraft(null),
|
|
978
|
+
onKeyDown: (event) => {
|
|
979
|
+
if (event.key === "Enter") {
|
|
980
|
+
event.preventDefault();
|
|
981
|
+
if (!hexDraft?.invalid) setOpen(false);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}), /* @__PURE__ */ jsx(IconButton, {
|
|
985
|
+
"aria-label": copied ? labels.copied : labels.copyColor,
|
|
986
|
+
title: copied ? labels.copied : labels.copyColor,
|
|
987
|
+
onClick: copyValue,
|
|
988
|
+
disabled: mixed,
|
|
989
|
+
className: "absolute right-1 top-1/2 size-5 -translate-y-1/2",
|
|
990
|
+
children: copied ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(Copy, {})
|
|
991
|
+
})]
|
|
992
|
+
})]
|
|
993
|
+
}),
|
|
994
|
+
hexDraft?.invalid && /* @__PURE__ */ jsx("p", {
|
|
995
|
+
id: `${hexId}-error`,
|
|
996
|
+
role: "alert",
|
|
997
|
+
className: "text-xs text-destructive",
|
|
998
|
+
children: labels.colorInvalid
|
|
999
|
+
})
|
|
1000
|
+
]
|
|
1001
|
+
})]
|
|
1002
|
+
}),
|
|
1003
|
+
/* @__PURE__ */ jsx("span", {
|
|
1004
|
+
className: "min-w-0 flex-1 truncate font-mono text-[10px] leading-4 text-muted-foreground",
|
|
1005
|
+
children: mixed ? labels.mixed : color ? value.toUpperCase() : labels.default
|
|
1006
|
+
}),
|
|
1007
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
1008
|
+
"aria-label": labels.resetColor,
|
|
1009
|
+
title: labels.resetColor,
|
|
1010
|
+
disabled: disabled || !mixed && !color,
|
|
1011
|
+
onClick: () => onValueChange(void 0),
|
|
1012
|
+
children: /* @__PURE__ */ jsx(RotateCcw, {})
|
|
1013
|
+
})
|
|
1014
|
+
]
|
|
1015
|
+
})]
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
//#endregion
|
|
1019
|
+
//#region src/autocomplete.tsx
|
|
1020
|
+
function AutocompletePopup({ className, children, ...props }) {
|
|
1021
|
+
return /* @__PURE__ */ jsx(Autocomplete.Portal, { children: /* @__PURE__ */ jsx(Autocomplete.Positioner, {
|
|
1022
|
+
sideOffset: 4,
|
|
1023
|
+
className: "z-50 outline-none",
|
|
1024
|
+
children: /* @__PURE__ */ jsx(Autocomplete.Popup, {
|
|
1025
|
+
className: cn("nesso-popup max-h-72 w-(--anchor-width) overflow-y-auto p-1", className),
|
|
1026
|
+
...props,
|
|
1027
|
+
children
|
|
1028
|
+
})
|
|
1029
|
+
}) });
|
|
1030
|
+
}
|
|
1031
|
+
function AutocompleteItem({ className, ...props }) {
|
|
1032
|
+
return /* @__PURE__ */ jsx(Autocomplete.Item, {
|
|
1033
|
+
className: cn("nesso-option cursor-default px-2.5 py-2", className),
|
|
1034
|
+
...props
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
function AutocompleteClear({ className, children, ...props }) {
|
|
1038
|
+
return /* @__PURE__ */ jsx(Autocomplete.Clear, {
|
|
1039
|
+
className: cn("nesso-button absolute top-1/2 right-1.5 flex size-5 -translate-y-1/2 items-center justify-center text-muted-foreground hover:bg-accent hover:text-foreground", className),
|
|
1040
|
+
...props,
|
|
1041
|
+
children: children ?? /* @__PURE__ */ jsx(X, { className: "size-3.5" })
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
//#endregion
|
|
1045
|
+
//#region src/section-heading.tsx
|
|
1046
|
+
function SectionHeading({ open, children, className, ...props }) {
|
|
1047
|
+
return /* @__PURE__ */ jsxs(Button, {
|
|
1048
|
+
...props,
|
|
1049
|
+
variant: "ghost",
|
|
1050
|
+
size: "sm",
|
|
1051
|
+
"aria-expanded": open,
|
|
1052
|
+
className: cn("nesso-section-heading w-full justify-start font-mono text-muted-foreground hover:bg-transparent hover:text-foreground active:bg-transparent", className),
|
|
1053
|
+
children: [/* @__PURE__ */ jsx(ChevronDown, { className: open ? "" : "-rotate-90" }), children]
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
//#endregion
|
|
1057
|
+
//#region src/action-icon.tsx
|
|
1058
|
+
const icons = {
|
|
1059
|
+
"arrow-right": ArrowRight,
|
|
1060
|
+
"book-open": BookOpen,
|
|
1061
|
+
"clipboard-paste": ClipboardPaste,
|
|
1062
|
+
copy: Copy,
|
|
1063
|
+
download: Download,
|
|
1064
|
+
"file-down": FileDown,
|
|
1065
|
+
"file-up": FileUp,
|
|
1066
|
+
folder: Folder,
|
|
1067
|
+
globe: Globe,
|
|
1068
|
+
layers: Layers,
|
|
1069
|
+
pencil: Pencil,
|
|
1070
|
+
play: Play,
|
|
1071
|
+
plus: Plus,
|
|
1072
|
+
refresh: RefreshCw,
|
|
1073
|
+
scissors: Scissors,
|
|
1074
|
+
search: Search,
|
|
1075
|
+
share: Share2,
|
|
1076
|
+
sparkles: Sparkles,
|
|
1077
|
+
upload: Upload,
|
|
1078
|
+
zap: Zap
|
|
1079
|
+
};
|
|
1080
|
+
function ActionIcon({ name, ...props }) {
|
|
1081
|
+
const Icon = (name !== void 0 ? icons[name] : void 0) ?? Zap;
|
|
1082
|
+
return /* @__PURE__ */ jsx(Icon, {
|
|
1083
|
+
"aria-hidden": "true",
|
|
1084
|
+
...props
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
//#endregion
|
|
1088
|
+
export { ActionIcon, Autocomplete, AutocompleteClear, AutocompleteItem, AutocompletePopup, Banner, Button, Collapsible, ColorPicker, Combobox, ComboboxItem, ComboboxPopup, ConfirmDialog, ContextLabel, Dialog, DialogActions, DialogPopup, Field, FieldHint, IconButton, Input, Kbd, Label, ListRow, ListRowButton, ListRowDetail, ListRowTitle, Menu, MenuItem, MenuPopup, MenuRadioItem, PanelHeader, Popover, PopoverPopup, PreferenceSelect, PromptForm, RevealActions, SectionHeading, SidePanel, Spinner, Tabs, TextPromptDialog, ToastViewport, contrastColor, presetColors, useMediaQuery };
|