@spear-ai/spectral 1.4.13 → 1.4.14

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.
@@ -1,216 +0,0 @@
1
- "use client";
2
- import "../styles/main.css";
3
- import { jsx as r, jsxs as I } from "react/jsx-runtime";
4
- import { CloseIcon as $ } from "../Icons/CloseIcon.js";
5
- import { cn as m } from "../utils/twUtils.js";
6
- import { c as j } from "../index-D29mdTf5.js";
7
- import { createContext as S, useContext as W, useState as N, useMemo as B, useCallback as k, cloneElement as z, useEffect as C, useRef as h, useLayoutEffect as M, isValidElement as O } from "react";
8
- import { createPortal as A } from "react-dom";
9
- import { R as F } from "../Combination-BtmnusWq.js";
10
- const P = S(null);
11
- function p() {
12
- const t = W(P);
13
- if (!t)
14
- throw new Error("Dialog components must be used within <Dialog>");
15
- return t;
16
- }
17
- function T(t) {
18
- return O(t) && typeof t.type != "string" ? !0 : O(t);
19
- }
20
- let E = 0;
21
- function Z({ isOpen: t, defaultOpen: o = !1, onOpenChange: e, children: n, modal: a = !1 }) {
22
- const [l, u] = N(o), s = t !== void 0, f = s ? t : l, b = B(
23
- () => ({
24
- contentId: `dialog-content-${++E}`,
25
- descriptionId: `dialog-description-${E}`,
26
- titleId: `dialog-title-${E}`
27
- }),
28
- []
29
- ), y = k(
30
- (c) => {
31
- s || u(c), e?.(c);
32
- },
33
- [s, e]
34
- ), D = B(
35
- () => ({
36
- modal: a,
37
- isOpen: f,
38
- setIsOpen: y,
39
- ...b
40
- }),
41
- [f, y, a, b]
42
- );
43
- return /* @__PURE__ */ r(P.Provider, { value: D, children: n });
44
- }
45
- function _({ children: t, asChild: o = !0, dataTestId: e }) {
46
- const { setIsOpen: n } = p(), a = k(() => {
47
- n(!0);
48
- }, [n]);
49
- if (!o)
50
- return /* @__PURE__ */ r("button", { "data-slot": "dialog-trigger", "data-testid": e, onClick: a, tabIndex: 0, children: t });
51
- if (!T(t))
52
- throw new Error("DialogTrigger expects a single React element as child");
53
- const l = t.props.onClick;
54
- return z(t, {
55
- onClick: (...u) => {
56
- l?.(...u), a();
57
- }
58
- });
59
- }
60
- function H({ children: t, asChild: o = !0, dataTestId: e }) {
61
- const { setIsOpen: n } = p(), a = k(() => {
62
- n(!1);
63
- }, [n]);
64
- if (!o)
65
- return /* @__PURE__ */ r("button", { className: "cursor-pointer focus-visible:outline-none outline-transparent focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1", "data-slot": "dialog-close", "data-testid": e, onClick: a, tabIndex: 0, children: t });
66
- if (!T(t))
67
- throw new Error("DialogClose expects a single React element as child");
68
- const l = t.props.onClick;
69
- return z(t, {
70
- onClick: (...u) => {
71
- l?.(...u), a();
72
- }
73
- });
74
- }
75
- function L({ children: t, container: o }) {
76
- const [e, n] = N(!1);
77
- return C(() => (n(!0), () => n(!1)), []), e ? A(t, o ?? document.body) : null;
78
- }
79
- function tt({ className: t, dataTestId: o }) {
80
- const { isOpen: e, setIsOpen: n } = p(), a = k(
81
- (l) => {
82
- l.target === l.currentTarget && n(!1);
83
- },
84
- [n]
85
- );
86
- return e ? /* @__PURE__ */ r(L, { children: /* @__PURE__ */ r(
87
- "div",
88
- {
89
- "aria-hidden": "true",
90
- className: m("fixed inset-0 z-40 bg-black/50 backdrop-blur-sm data-[state=open]:animate-in data-[state=open]:fade-in-0", "data-[state=closed]:animate-out data-[state=closed]:fade-out-0", t),
91
- "data-state": e ? "open" : "closed",
92
- "data-testid": o,
93
- onClick: a
94
- }
95
- ) }) : null;
96
- }
97
- const U = j(
98
- [
99
- "fixed left-1/2 top-1/2 z-50 w-full -translate-x-1/2 -translate-y-1/2 rounded-lg shadow-lg outline-none data-[state=open]:animate-in data-[state=open]:fade-in-0",
100
- "data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 max-h-[80vh] overflow-y-auto"
101
- ],
102
- {
103
- variants: {
104
- size: {
105
- sm: "max-w-sm",
106
- md: "max-w-md",
107
- lg: "max-w-lg",
108
- xl: "max-w-xl",
109
- "2xl": "max-w-2xl"
110
- }
111
- },
112
- defaultVariants: {
113
- size: "md"
114
- }
115
- }
116
- );
117
- function et({ children: t, className: o, dataTestId: e, onEscapeKeyDown: n, onInteractOutside: a, onPointerDownOutside: l, size: u }) {
118
- const { isOpen: s, setIsOpen: f, contentId: b, titleId: y, descriptionId: D, modal: c } = p(), g = h(null), R = h(null), x = h(null), v = h(!1);
119
- return C(() => {
120
- if (!s) {
121
- v.current && x.current && typeof x.current.focus == "function" && x.current.focus(), x.current = null, v.current = !1;
122
- return;
123
- }
124
- if (!g.current || v.current) return;
125
- v.current = !0;
126
- const d = g.current;
127
- x.current = document.activeElement, setTimeout(() => {
128
- if (!d || !g.current) return;
129
- const i = document.activeElement;
130
- (!d.contains(i) || i === document.body) && d.focus();
131
- }, 0);
132
- }, [s, f]), C(() => {
133
- if (!s) return;
134
- const d = (i) => {
135
- i.key === "Escape" && (n?.(i), a?.(i), i.defaultPrevented || (i.preventDefault(), f(!1)));
136
- };
137
- return document.addEventListener("keydown", d, { capture: !0 }), () => {
138
- document.removeEventListener("keydown", d, { capture: !0 });
139
- };
140
- }, [s, n, a]), C(() => {
141
- if (!s) return;
142
- const d = (i) => {
143
- const w = i.target;
144
- g.current && !g.current.contains(w) && (l?.(i), a?.(i), !c && !i.defaultPrevented && f(!1));
145
- };
146
- return document.addEventListener("pointerdown", d), () => document.removeEventListener("pointerdown", d);
147
- }, [s, l, a, f, c]), M(() => {
148
- if (!s || !c || typeof window > "u") return;
149
- const d = document.body.style.overflow, i = document.body.style.paddingRight, w = window.innerWidth - document.documentElement.clientWidth;
150
- if (document.body.style.overflow = "hidden", w > 0) {
151
- const V = window.getComputedStyle(document.body).paddingRight;
152
- document.body.style.paddingRight = `calc(${V} + ${w}px)`;
153
- }
154
- return () => {
155
- document.body.style.overflow = d, document.body.style.paddingRight = i;
156
- };
157
- }, [s, c]), s ? /* @__PURE__ */ r(L, { children: /* @__PURE__ */ I(
158
- "div",
159
- {
160
- "aria-describedby": D,
161
- "aria-labelledby": y,
162
- "aria-modal": c ? "true" : void 0,
163
- className: m(U({ size: u }), o),
164
- "data-slot": "dialog-content",
165
- "data-state": s ? "open" : "closed",
166
- "data-testid": e,
167
- id: b,
168
- ref: g,
169
- role: "dialog",
170
- tabIndex: -1,
171
- children: [
172
- /* @__PURE__ */ r(H, { asChild: !0, children: /* @__PURE__ */ I(
173
- "button",
174
- {
175
- "aria-label": "Close dialog",
176
- className: m("absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100", "focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none cursor-pointer"),
177
- "data-slot": "dialog-close",
178
- "data-testid": "spectral-dialog-close-icon",
179
- children: [
180
- /* @__PURE__ */ r($, { size: 16 }),
181
- /* @__PURE__ */ r("span", { className: "sr-only", children: "Close" })
182
- ]
183
- }
184
- ) }),
185
- /* @__PURE__ */ r(F, { shards: [R], children: /* @__PURE__ */ r("div", { ref: R, children: t }) })
186
- ]
187
- }
188
- ) }) : null;
189
- }
190
- function nt({ children: t, className: o, dataTestId: e }) {
191
- const { titleId: n } = p();
192
- return /* @__PURE__ */ r("h2", { className: m("text-base font-semibold leading-none tracking-tight", o), "data-slot": "dialog-title", "data-testid": e, id: n, children: t });
193
- }
194
- function ot({ children: t, className: o, dataTestId: e }) {
195
- const { descriptionId: n } = p();
196
- return /* @__PURE__ */ r("p", { className: m("text-sm text-text-secondary", o), "data-slot": "dialog-description", "data-testid": e, id: n, children: t });
197
- }
198
- function at({ children: t, className: o, dataTestId: e }) {
199
- return /* @__PURE__ */ r("div", { className: m("flex flex-col space-y-1.5 text-center text-left", o), "data-slot": "dialog-header", "data-testid": e, children: t });
200
- }
201
- function it({ children: t, className: o, dataTestId: e }) {
202
- return /* @__PURE__ */ r("div", { className: m("flex flex-col-reverse flex-row justify-end space-x-2", o), "data-slot": "dialog-footer", "data-testid": e, children: t });
203
- }
204
- export {
205
- Z as DialogBase,
206
- H as DialogCloseBase,
207
- et as DialogContentBase,
208
- ot as DialogDescriptionBase,
209
- it as DialogFooterBase,
210
- at as DialogHeaderBase,
211
- tt as DialogOverlayBase,
212
- L as DialogPortalBase,
213
- nt as DialogTitleBase,
214
- _ as DialogTriggerBase,
215
- p as useDialogContext
216
- };