@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.
@@ -4,24 +4,24 @@ export type DialogBaseProps = {
4
4
  children: ReactNode;
5
5
  dataTestId?: string;
6
6
  defaultOpen?: boolean;
7
- open?: boolean;
7
+ isOpen?: boolean;
8
8
  modal?: boolean;
9
- onOpenChange?: (open: boolean) => void;
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
- open: boolean;
17
- setOpen: (open: boolean) => void;
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({ open: controlledOpen, defaultOpen, onOpenChange, children, modal }: DialogBaseProps): import("react/jsx-runtime").JSX.Element;
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 r, jsxs as I } from "react/jsx-runtime";
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 A, useState as z, useMemo as B, useCallback as k, cloneElement as R, useEffect as y, useRef as D, isValidElement as N } from "react";
8
- import { createPortal as $ } from "react-dom";
9
- const T = j(null);
10
- function m() {
11
- const t = A(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 O(t) {
17
- return N(t) && typeof t.type != "string" ? !0 : N(t);
16
+ function R(t) {
17
+ return B(t) && typeof t.type != "string" ? !0 : B(t);
18
18
  }
19
19
  let h = 0;
20
- function Q({ open: t, defaultOpen: o = !1, onOpenChange: e, children: n, modal: a = !0 }) {
21
- const [l, d] = z(o), s = t !== void 0, u = s ? t : l, b = B(
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 = k(
28
+ ), C = w(
29
29
  (p) => {
30
- s || d(p), e?.(p);
30
+ r || d(p), e?.(p);
31
31
  },
32
- [s, e]
33
- ), w = B(
32
+ [r, e]
33
+ ), y = I(
34
34
  () => ({
35
35
  modal: a,
36
- open: u,
37
- setOpen: C,
36
+ isOpen: u,
37
+ setIsOpen: C,
38
38
  ...b
39
39
  }),
40
40
  [u, C, a, b]
41
41
  );
42
- return /* @__PURE__ */ r(T.Provider, { value: w, children: n });
42
+ return /* @__PURE__ */ s(z.Provider, { value: y, children: n });
43
43
  }
44
- function W({ children: t, asChild: o = !0, dataTestId: e }) {
45
- const { setOpen: n } = m(), a = k(() => {
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__ */ r("button", { "data-slot": "dialog-trigger", "data-testid": e, onClick: a, tabIndex: 0, children: t });
50
- if (!O(t))
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 R(t, {
53
+ return O(t, {
54
54
  onClick: (...d) => {
55
55
  l?.(...d), a();
56
56
  }
57
57
  });
58
58
  }
59
- function M({ children: t, asChild: o = !0, dataTestId: e }) {
60
- const { setOpen: n } = m(), a = k(() => {
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__ */ 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 });
65
- if (!O(t))
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 R(t, {
68
+ return O(t, {
69
69
  onClick: (...d) => {
70
70
  l?.(...d), a();
71
71
  }
72
72
  });
73
73
  }
74
- function P({ children: t, container: o }) {
75
- const [e, n] = z(!1);
76
- return y(() => (n(!0), () => n(!1)), []), e ? $(t, o ?? document.body) : null;
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 X({ className: t, dataTestId: o }) {
79
- const { open: e, setOpen: n } = m(), a = k(
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__ */ r(P, { children: /* @__PURE__ */ r(
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 Y({ children: t, className: o, dataTestId: e, onEscapeKeyDown: n, onInteractOutside: a, onPointerDownOutside: l, size: d }) {
117
- const { open: s, setOpen: u, contentId: b, titleId: C, descriptionId: w, modal: p } = m(), g = D(null), x = D(null), v = D(!1);
118
- return y(() => {
119
- if (!s) {
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 (!g.current || v.current) return;
123
+ if (!m.current || v.current) return;
124
124
  v.current = !0;
125
- const c = g.current;
125
+ const c = m.current;
126
126
  x.current = document.activeElement, setTimeout(() => {
127
- if (!c || !g.current) return;
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
- }, [s]), y(() => {
132
- if (!s) return;
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
- }, [s, n, a, u]), y(() => {
140
- if (!s) return;
139
+ }, [r, n, a]), k(() => {
140
+ if (!r) return;
141
141
  const c = (i) => {
142
- const E = i.target;
143
- g.current && !g.current.contains(E) && (E.closest("[role='dialog']") !== null || (l?.(i), a?.(i), !p && !i.defaultPrevented && u(!1)));
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
- }, [s, l, a, u, p]), s ? /* @__PURE__ */ r(P, { children: /* @__PURE__ */ I(
146
+ }, [r, l, a, u, p]), r ? /* @__PURE__ */ s(T, { children: /* @__PURE__ */ E(
147
147
  "div",
148
148
  {
149
- "aria-describedby": w,
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": s ? "open" : "closed",
154
+ "data-state": r ? "open" : "closed",
155
155
  "data-testid": e,
156
156
  id: b,
157
- ref: g,
157
+ ref: m,
158
158
  role: "dialog",
159
159
  tabIndex: -1,
160
160
  children: [
161
- /* @__PURE__ */ r(M, { asChild: !0, children: /* @__PURE__ */ I(
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__ */ r(V, { size: 16 }),
170
- /* @__PURE__ */ r("span", { className: "sr-only", children: "Close" })
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 { titleId: n } = m();
181
- return /* @__PURE__ */ r("h2", { className: f("text-base font-semibold leading-none tracking-tight", o), "data-slot": "dialog-title", "data-testid": e, id: n, children: t });
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
- const { descriptionId: n } = m();
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__ */ r("div", { className: f("flex flex-col space-y-1.5 text-center text-left", o), "data-slot": "dialog-header", "data-testid": e, children: t });
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
- Q as DialogBase,
195
- M as DialogCloseBase,
196
- Y as DialogContentBase,
197
- _ as DialogDescriptionBase,
198
- et as DialogFooterBase,
199
- tt as DialogHeaderBase,
200
- X as DialogOverlayBase,
201
- P as DialogPortalBase,
202
- Z as DialogTitleBase,
203
- W as DialogTriggerBase,
204
- m as useDialogContext
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 v({ ...a }) {
6
+ function h({ ...a }) {
7
7
  return /* @__PURE__ */ o(g, { "data-slot": "dialog", "data-testid": "spectral-dialog", ...a });
8
8
  }
9
- function w({ dataTestId: a, ...t }) {
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 h({ ...a }) {
12
+ function w({ ...a }) {
13
13
  return /* @__PURE__ */ o(x, { "data-slot": "dialog-portal", "data-testid": "dialog-portal", ...a });
14
14
  }
15
- function z({ dataTestId: a, ...t }) {
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 C({ className: a, dataTestId: t, ...e }) {
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
- v as Dialog,
69
- z as DialogClose,
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
- C as DialogOverlay,
75
- h as DialogPortal,
74
+ z as DialogOverlay,
75
+ w as DialogPortal,
76
76
  O as DialogTitle,
77
- w as DialogTrigger
77
+ v as DialogTrigger
78
78
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spear-ai/spectral",
3
- "version": "1.4.8",
3
+ "version": "1.4.9",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "repository": {