@spear-ai/spectral 1.4.8 → 1.4.9
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/dist/Dialog/DialogBase.d.ts +5 -5
- package/dist/Dialog/DialogBase.js +72 -72
- package/dist/Dialog.js +11 -11
- package/package.json +1 -1
|
@@ -4,24 +4,24 @@ export type DialogBaseProps = {
|
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
dataTestId?: string;
|
|
6
6
|
defaultOpen?: boolean;
|
|
7
|
-
|
|
7
|
+
isOpen?: boolean;
|
|
8
8
|
modal?: boolean;
|
|
9
|
-
onOpenChange?: (
|
|
9
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
10
10
|
};
|
|
11
11
|
export type DialogContextValue = {
|
|
12
12
|
contentId: string;
|
|
13
13
|
dataTestId?: string;
|
|
14
14
|
descriptionId: string;
|
|
15
15
|
modal: boolean;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
isOpen: boolean;
|
|
17
|
+
setIsOpen: (isOpen: boolean) => void;
|
|
18
18
|
titleId: string;
|
|
19
19
|
};
|
|
20
20
|
export type TriggerableElement = ReactElement<{
|
|
21
21
|
onClick?: (...args: unknown[]) => void;
|
|
22
22
|
}>;
|
|
23
23
|
export declare function useDialogContext(): DialogContextValue;
|
|
24
|
-
export declare function DialogBase({
|
|
24
|
+
export declare function DialogBase({ isOpen: controlledIsOpen, defaultOpen, onOpenChange, children, modal }: DialogBaseProps): import("react/jsx-runtime").JSX.Element;
|
|
25
25
|
type DialogTriggerProps = {
|
|
26
26
|
asChild?: boolean;
|
|
27
27
|
children: ReactNode;
|
|
@@ -1,88 +1,88 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "../styles/main.css";
|
|
3
|
-
import { jsx as
|
|
3
|
+
import { jsx as s, jsxs as E } from "react/jsx-runtime";
|
|
4
4
|
import { CloseIcon as V } from "../Icons/CloseIcon.js";
|
|
5
5
|
import { cn as f } from "../utils/twUtils.js";
|
|
6
6
|
import { c as L } from "../index-D29mdTf5.js";
|
|
7
|
-
import { createContext as j, useContext as
|
|
8
|
-
import { createPortal as
|
|
9
|
-
const
|
|
10
|
-
function
|
|
11
|
-
const t =
|
|
7
|
+
import { createContext as j, useContext as $, useState as N, useMemo as I, useCallback as w, cloneElement as O, useEffect as k, useRef as D, isValidElement as B } from "react";
|
|
8
|
+
import { createPortal as M } from "react-dom";
|
|
9
|
+
const z = j(null);
|
|
10
|
+
function g() {
|
|
11
|
+
const t = $(z);
|
|
12
12
|
if (!t)
|
|
13
13
|
throw new Error("Dialog components must be used within <Dialog>");
|
|
14
14
|
return t;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
return
|
|
16
|
+
function R(t) {
|
|
17
|
+
return B(t) && typeof t.type != "string" ? !0 : B(t);
|
|
18
18
|
}
|
|
19
19
|
let h = 0;
|
|
20
|
-
function
|
|
21
|
-
const [l, d] =
|
|
20
|
+
function K({ isOpen: t, defaultOpen: o = !1, onOpenChange: e, children: n, modal: a = !0 }) {
|
|
21
|
+
const [l, d] = N(o), r = t !== void 0, u = r ? t : l, b = I(
|
|
22
22
|
() => ({
|
|
23
23
|
contentId: `dialog-content-${++h}`,
|
|
24
24
|
descriptionId: `dialog-description-${h}`,
|
|
25
25
|
titleId: `dialog-title-${h}`
|
|
26
26
|
}),
|
|
27
27
|
[]
|
|
28
|
-
), C =
|
|
28
|
+
), C = w(
|
|
29
29
|
(p) => {
|
|
30
|
-
|
|
30
|
+
r || d(p), e?.(p);
|
|
31
31
|
},
|
|
32
|
-
[
|
|
33
|
-
),
|
|
32
|
+
[r, e]
|
|
33
|
+
), y = I(
|
|
34
34
|
() => ({
|
|
35
35
|
modal: a,
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
isOpen: u,
|
|
37
|
+
setIsOpen: C,
|
|
38
38
|
...b
|
|
39
39
|
}),
|
|
40
40
|
[u, C, a, b]
|
|
41
41
|
);
|
|
42
|
-
return /* @__PURE__ */
|
|
42
|
+
return /* @__PURE__ */ s(z.Provider, { value: y, children: n });
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
const {
|
|
44
|
+
function Q({ children: t, asChild: o = !0, dataTestId: e }) {
|
|
45
|
+
const { setIsOpen: n } = g(), a = w(() => {
|
|
46
46
|
n(!0);
|
|
47
47
|
}, [n]);
|
|
48
48
|
if (!o)
|
|
49
|
-
return /* @__PURE__ */
|
|
50
|
-
if (!
|
|
49
|
+
return /* @__PURE__ */ s("button", { "data-slot": "dialog-trigger", "data-testid": e, onClick: a, tabIndex: 0, children: t });
|
|
50
|
+
if (!R(t))
|
|
51
51
|
throw new Error("DialogTrigger expects a single React element as child");
|
|
52
52
|
const l = t.props.onClick;
|
|
53
|
-
return
|
|
53
|
+
return O(t, {
|
|
54
54
|
onClick: (...d) => {
|
|
55
55
|
l?.(...d), a();
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
const {
|
|
59
|
+
function A({ children: t, asChild: o = !0, dataTestId: e }) {
|
|
60
|
+
const { setIsOpen: n } = g(), a = w(() => {
|
|
61
61
|
n(!1);
|
|
62
62
|
}, [n]);
|
|
63
63
|
if (!o)
|
|
64
|
-
return /* @__PURE__ */
|
|
65
|
-
if (!
|
|
64
|
+
return /* @__PURE__ */ s("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 });
|
|
65
|
+
if (!R(t))
|
|
66
66
|
throw new Error("DialogClose expects a single React element as child");
|
|
67
67
|
const l = t.props.onClick;
|
|
68
|
-
return
|
|
68
|
+
return O(t, {
|
|
69
69
|
onClick: (...d) => {
|
|
70
70
|
l?.(...d), a();
|
|
71
71
|
}
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
const [e, n] =
|
|
76
|
-
return
|
|
74
|
+
function T({ children: t, container: o }) {
|
|
75
|
+
const [e, n] = N(!1);
|
|
76
|
+
return k(() => (n(!0), () => n(!1)), []), e ? M(t, o ?? document.body) : null;
|
|
77
77
|
}
|
|
78
|
-
function
|
|
79
|
-
const {
|
|
78
|
+
function W({ className: t, dataTestId: o }) {
|
|
79
|
+
const { isOpen: e, setIsOpen: n } = g(), a = w(
|
|
80
80
|
(l) => {
|
|
81
81
|
l.target === l.currentTarget && n(!1);
|
|
82
82
|
},
|
|
83
83
|
[n]
|
|
84
84
|
);
|
|
85
|
-
return e ? /* @__PURE__ */
|
|
85
|
+
return e ? /* @__PURE__ */ s(T, { children: /* @__PURE__ */ s(
|
|
86
86
|
"div",
|
|
87
87
|
{
|
|
88
88
|
"aria-hidden": "true",
|
|
@@ -113,52 +113,52 @@ const F = L(
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
);
|
|
116
|
-
function
|
|
117
|
-
const {
|
|
118
|
-
return
|
|
119
|
-
if (!
|
|
116
|
+
function X({ children: t, className: o, dataTestId: e, onEscapeKeyDown: n, onInteractOutside: a, onPointerDownOutside: l, size: d }) {
|
|
117
|
+
const { isOpen: r, setIsOpen: u, contentId: b, titleId: C, descriptionId: y, modal: p } = g(), m = D(null), x = D(null), v = D(!1);
|
|
118
|
+
return k(() => {
|
|
119
|
+
if (!r) {
|
|
120
120
|
v.current && x.current && typeof x.current.focus == "function" && x.current.focus(), x.current = null, v.current = !1;
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
|
-
if (!
|
|
123
|
+
if (!m.current || v.current) return;
|
|
124
124
|
v.current = !0;
|
|
125
|
-
const c =
|
|
125
|
+
const c = m.current;
|
|
126
126
|
x.current = document.activeElement, setTimeout(() => {
|
|
127
|
-
if (!c || !
|
|
127
|
+
if (!c || !m.current) return;
|
|
128
128
|
const i = document.activeElement;
|
|
129
129
|
(!c.contains(i) || i === document.body) && c.focus();
|
|
130
130
|
}, 0);
|
|
131
|
-
}, [
|
|
132
|
-
if (!
|
|
131
|
+
}, [r, u]), k(() => {
|
|
132
|
+
if (!r) return;
|
|
133
133
|
const c = (i) => {
|
|
134
134
|
i.key === "Escape" && (n?.(i), a?.(i), i.defaultPrevented || (i.preventDefault(), u(!1)));
|
|
135
135
|
};
|
|
136
136
|
return document.addEventListener("keydown", c, { capture: !0 }), () => {
|
|
137
137
|
document.removeEventListener("keydown", c, { capture: !0 });
|
|
138
138
|
};
|
|
139
|
-
}, [
|
|
140
|
-
if (!
|
|
139
|
+
}, [r, n, a]), k(() => {
|
|
140
|
+
if (!r) return;
|
|
141
141
|
const c = (i) => {
|
|
142
|
-
const
|
|
143
|
-
|
|
142
|
+
const P = i.target;
|
|
143
|
+
m.current && !m.current.contains(P) && (l?.(i), a?.(i), !p && !i.defaultPrevented && u(!1));
|
|
144
144
|
};
|
|
145
145
|
return document.addEventListener("pointerdown", c), () => document.removeEventListener("pointerdown", c);
|
|
146
|
-
}, [
|
|
146
|
+
}, [r, l, a, u, p]), r ? /* @__PURE__ */ s(T, { children: /* @__PURE__ */ E(
|
|
147
147
|
"div",
|
|
148
148
|
{
|
|
149
|
-
"aria-describedby":
|
|
149
|
+
"aria-describedby": y,
|
|
150
150
|
"aria-labelledby": C,
|
|
151
151
|
"aria-modal": "true",
|
|
152
152
|
className: f(F({ size: d }), o),
|
|
153
153
|
"data-slot": "dialog-content",
|
|
154
|
-
"data-state":
|
|
154
|
+
"data-state": r ? "open" : "closed",
|
|
155
155
|
"data-testid": e,
|
|
156
156
|
id: b,
|
|
157
|
-
ref:
|
|
157
|
+
ref: m,
|
|
158
158
|
role: "dialog",
|
|
159
159
|
tabIndex: -1,
|
|
160
160
|
children: [
|
|
161
|
-
/* @__PURE__ */
|
|
161
|
+
/* @__PURE__ */ s(A, { asChild: !0, children: /* @__PURE__ */ E(
|
|
162
162
|
"button",
|
|
163
163
|
{
|
|
164
164
|
"aria-label": "Close dialog",
|
|
@@ -166,8 +166,8 @@ function Y({ children: t, className: o, dataTestId: e, onEscapeKeyDown: n, onInt
|
|
|
166
166
|
"data-slot": "dialog-close",
|
|
167
167
|
"data-testid": "spectral-dialog-close-icon",
|
|
168
168
|
children: [
|
|
169
|
-
/* @__PURE__ */
|
|
170
|
-
/* @__PURE__ */
|
|
169
|
+
/* @__PURE__ */ s(V, { size: 16 }),
|
|
170
|
+
/* @__PURE__ */ s("span", { className: "sr-only", children: "Close" })
|
|
171
171
|
]
|
|
172
172
|
}
|
|
173
173
|
) }),
|
|
@@ -176,30 +176,30 @@ function Y({ children: t, className: o, dataTestId: e, onEscapeKeyDown: n, onInt
|
|
|
176
176
|
}
|
|
177
177
|
) }) : null;
|
|
178
178
|
}
|
|
179
|
+
function Y({ children: t, className: o, dataTestId: e }) {
|
|
180
|
+
const { titleId: n } = g();
|
|
181
|
+
return /* @__PURE__ */ s("h2", { className: f("text-base font-semibold leading-none tracking-tight", o), "data-slot": "dialog-title", "data-testid": e, id: n, children: t });
|
|
182
|
+
}
|
|
179
183
|
function Z({ children: t, className: o, dataTestId: e }) {
|
|
180
|
-
const {
|
|
181
|
-
return /* @__PURE__ */
|
|
184
|
+
const { descriptionId: n } = g();
|
|
185
|
+
return /* @__PURE__ */ s("p", { className: f("text-sm text-text-secondary", o), "data-slot": "dialog-description", "data-testid": e, id: n, children: t });
|
|
182
186
|
}
|
|
183
187
|
function _({ children: t, className: o, dataTestId: e }) {
|
|
184
|
-
|
|
185
|
-
return /* @__PURE__ */ r("p", { className: f("text-sm text-text-secondary", o), "data-slot": "dialog-description", "data-testid": e, id: n, children: t });
|
|
188
|
+
return /* @__PURE__ */ s("div", { className: f("flex flex-col space-y-1.5 text-center text-left", o), "data-slot": "dialog-header", "data-testid": e, children: t });
|
|
186
189
|
}
|
|
187
190
|
function tt({ children: t, className: o, dataTestId: e }) {
|
|
188
|
-
return /* @__PURE__ */
|
|
189
|
-
}
|
|
190
|
-
function et({ children: t, className: o, dataTestId: e }) {
|
|
191
|
-
return /* @__PURE__ */ r("div", { className: f("flex flex-col-reverse flex-row justify-end space-x-2", o), "data-slot": "dialog-footer", "data-testid": e, children: t });
|
|
191
|
+
return /* @__PURE__ */ s("div", { className: f("flex flex-col-reverse flex-row justify-end space-x-2", o), "data-slot": "dialog-footer", "data-testid": e, children: t });
|
|
192
192
|
}
|
|
193
193
|
export {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
194
|
+
K as DialogBase,
|
|
195
|
+
A as DialogCloseBase,
|
|
196
|
+
X as DialogContentBase,
|
|
197
|
+
Z as DialogDescriptionBase,
|
|
198
|
+
tt as DialogFooterBase,
|
|
199
|
+
_ as DialogHeaderBase,
|
|
200
|
+
W as DialogOverlayBase,
|
|
201
|
+
T as DialogPortalBase,
|
|
202
|
+
Y as DialogTitleBase,
|
|
203
|
+
Q as DialogTriggerBase,
|
|
204
|
+
g as useDialogContext
|
|
205
205
|
};
|
package/dist/Dialog.js
CHANGED
|
@@ -3,19 +3,19 @@ import { jsx as o, Fragment as n } from "react/jsx-runtime";
|
|
|
3
3
|
import { DialogBase as g, DialogCloseBase as c, DialogContentBase as f, DialogDescriptionBase as u, DialogFooterBase as m, DialogHeaderBase as p, DialogOverlayBase as D, DialogPortalBase as x, DialogTitleBase as T, DialogTriggerBase as B } from "./Dialog/DialogBase.js";
|
|
4
4
|
import { cn as l } from "./utils/twUtils.js";
|
|
5
5
|
import "react";
|
|
6
|
-
function
|
|
6
|
+
function h({ ...a }) {
|
|
7
7
|
return /* @__PURE__ */ o(g, { "data-slot": "dialog", "data-testid": "spectral-dialog", ...a });
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
return /* @__PURE__ */ o(B, { "data-slot": "dialog-trigger", dataTestId: a || "dialog-trigger", ...t });
|
|
9
|
+
function v({ dataTestId: a, ...t }) {
|
|
10
|
+
return /* @__PURE__ */ o(B, { asChild: !0, "data-slot": "dialog-trigger", dataTestId: a || "dialog-trigger", ...t });
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function w({ ...a }) {
|
|
13
13
|
return /* @__PURE__ */ o(x, { "data-slot": "dialog-portal", "data-testid": "dialog-portal", ...a });
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function C({ dataTestId: a, ...t }) {
|
|
16
16
|
return /* @__PURE__ */ o(c, { "data-slot": "dialog-close", dataTestId: a || "dialog-close", ...t });
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function z({ className: a, dataTestId: t, ...e }) {
|
|
19
19
|
return /* @__PURE__ */ o(
|
|
20
20
|
D,
|
|
21
21
|
{
|
|
@@ -65,14 +65,14 @@ function P({ className: a, dataTestId: t, ...e }) {
|
|
|
65
65
|
return /* @__PURE__ */ o(u, { className: l("text-muted-foreground text-sm", a), "data-slot": "dialog-description", dataTestId: t || "dialog-description", ...e });
|
|
66
66
|
}
|
|
67
67
|
export {
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
h as Dialog,
|
|
69
|
+
C as DialogClose,
|
|
70
70
|
F as DialogContent,
|
|
71
71
|
P as DialogDescription,
|
|
72
72
|
H as DialogFooter,
|
|
73
73
|
j as DialogHeader,
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
z as DialogOverlay,
|
|
75
|
+
w as DialogPortal,
|
|
76
76
|
O as DialogTitle,
|
|
77
|
-
|
|
77
|
+
v as DialogTrigger
|
|
78
78
|
};
|