@perspective-ai/sdk-react 0.0.0-pr-21-20260224144030

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.
@@ -0,0 +1,175 @@
1
+ import { EmbedConfig, EmbedHandle, FloatHandle, TriggerConfig, ShowOnce } from '@perspective-ai/sdk';
2
+ export { AutoOpenConfig, BrandColors, EmbedConfig, EmbedError, EmbedHandle, FloatHandle, ShowOnce, ThemeValue, TriggerConfig } from '@perspective-ai/sdk';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { HTMLAttributes, RefObject } from 'react';
5
+
6
+ /** Options for usePopup hook */
7
+ interface UsePopupOptions extends Omit<EmbedConfig, "type"> {
8
+ /** Controlled open state */
9
+ open?: boolean;
10
+ /** Callback when open state changes */
11
+ onOpenChange?: (open: boolean) => void;
12
+ }
13
+ /** Return type for usePopup hook */
14
+ interface UsePopupReturn {
15
+ /** Open the popup */
16
+ open: () => void;
17
+ /** Close the popup */
18
+ close: () => void;
19
+ /** Toggle the popup */
20
+ toggle: () => void;
21
+ /** Whether the popup is currently open */
22
+ isOpen: boolean;
23
+ /** The underlying SDK handle (null when closed) */
24
+ handle: EmbedHandle | null;
25
+ }
26
+ /**
27
+ * Headless hook for programmatic popup control.
28
+ * Use this when you need custom trigger elements or programmatic control.
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * // Basic usage with custom trigger
33
+ * const { open, isOpen } = usePopup({ researchId: "abc" });
34
+ * <MyCustomButton onClick={open}>Open Survey</MyCustomButton>
35
+ *
36
+ * // Controlled mode
37
+ * const [isOpen, setIsOpen] = useState(false);
38
+ * const popup = usePopup({
39
+ * researchId: "abc",
40
+ * open: isOpen,
41
+ * onOpenChange: setIsOpen
42
+ * });
43
+ * ```
44
+ */
45
+ declare function usePopup(options: UsePopupOptions): UsePopupReturn;
46
+
47
+ /** Options for useSlider hook */
48
+ interface UseSliderOptions extends Omit<EmbedConfig, "type"> {
49
+ /** Controlled open state */
50
+ open?: boolean;
51
+ /** Callback when open state changes */
52
+ onOpenChange?: (open: boolean) => void;
53
+ }
54
+ /** Return type for useSlider hook */
55
+ interface UseSliderReturn {
56
+ /** Open the slider */
57
+ open: () => void;
58
+ /** Close the slider */
59
+ close: () => void;
60
+ /** Toggle the slider */
61
+ toggle: () => void;
62
+ /** Whether the slider is currently open */
63
+ isOpen: boolean;
64
+ /** The underlying SDK handle (null when closed) */
65
+ handle: EmbedHandle | null;
66
+ }
67
+ /**
68
+ * Headless hook for programmatic slider control.
69
+ * Use this when you need custom trigger elements or programmatic control.
70
+ *
71
+ * @example
72
+ * ```tsx
73
+ * const { open, isOpen } = useSlider({ researchId: "abc" });
74
+ * <MyCustomButton onClick={open}>Give Feedback</MyCustomButton>
75
+ * ```
76
+ */
77
+ declare function useSlider(options: UseSliderOptions): UseSliderReturn;
78
+
79
+ /** Options for useFloatBubble hook */
80
+ interface UseFloatBubbleOptions extends Omit<EmbedConfig, "type"> {
81
+ /** Controlled open state */
82
+ open?: boolean;
83
+ /** Callback when open state changes */
84
+ onOpenChange?: (open: boolean) => void;
85
+ }
86
+ /** Return type for useFloatBubble hook */
87
+ interface UseFloatBubbleReturn {
88
+ /** Open the float bubble window */
89
+ open: () => void;
90
+ /** Close the float bubble window */
91
+ close: () => void;
92
+ /** Toggle the float bubble window */
93
+ toggle: () => void;
94
+ /** Unmount the float bubble entirely */
95
+ unmount: () => void;
96
+ /** Whether the float bubble window is currently open */
97
+ isOpen: boolean;
98
+ /** The underlying SDK handle (null until mounted) */
99
+ handle: FloatHandle | null;
100
+ }
101
+ /**
102
+ * Headless hook for float bubble lifecycle management.
103
+ * Creates a floating bubble button that expands into a chat window.
104
+ * The bubble mounts on component mount and unmounts on component unmount.
105
+ *
106
+ * @example
107
+ * ```tsx
108
+ * // Basic usage - bubble mounts on component mount
109
+ * useFloatBubble({ researchId: "abc" });
110
+ *
111
+ * // With programmatic control
112
+ * const { open, close, isOpen } = useFloatBubble({ researchId: "abc" });
113
+ * <button onClick={open}>Open Chat</button>
114
+ * ```
115
+ */
116
+ declare function useFloatBubble(options: UseFloatBubbleOptions): UseFloatBubbleReturn;
117
+
118
+ interface UseAutoOpenOptions extends Omit<EmbedConfig, "type" | "autoOpen"> {
119
+ trigger: TriggerConfig;
120
+ showOnce?: ShowOnce;
121
+ }
122
+ interface UseAutoOpenReturn {
123
+ /** Cancel the pending trigger */
124
+ cancel: () => void;
125
+ /** Whether the trigger has fired */
126
+ triggered: boolean;
127
+ }
128
+ declare function useAutoOpen(options: UseAutoOpenOptions): UseAutoOpenReturn;
129
+
130
+ type Theme = "light" | "dark";
131
+ type ThemeInput = "light" | "dark" | "system";
132
+ /**
133
+ * Hook to resolve theme based on override and system preference.
134
+ * Listens for system preference changes when theme is "system".
135
+ */
136
+ declare function useThemeSync(theme?: ThemeInput): Theme;
137
+
138
+ declare function useStableCallback<T extends ((...args: any[]) => any) | undefined>(callback: T): T;
139
+
140
+ interface WidgetProps extends Omit<EmbedConfig, "type">, Omit<HTMLAttributes<HTMLDivElement>, "onError" | "onSubmit"> {
141
+ /** Ref to access the embed handle for programmatic control */
142
+ embedRef?: RefObject<EmbedHandle | null>;
143
+ }
144
+ /**
145
+ * Inline widget embed component.
146
+ * Renders the interview directly in a container.
147
+ */
148
+ declare function Widget({ researchId, params, brand, theme, host, onReady, onSubmit, onNavigate, onClose, onError, embedRef, className, style, ...divProps }: WidgetProps): react_jsx_runtime.JSX.Element;
149
+
150
+ interface FullpageProps extends Omit<EmbedConfig, "type"> {
151
+ /** Ref to access the embed handle for programmatic control */
152
+ embedRef?: RefObject<EmbedHandle | null>;
153
+ }
154
+ /**
155
+ * Full viewport embed component.
156
+ * Takes over the entire screen with the interview.
157
+ */
158
+ declare function Fullpage({ researchId, params, brand, theme, host, onReady, onSubmit, onNavigate, onClose, onError, embedRef, }: FullpageProps): null;
159
+
160
+ interface FloatBubbleProps extends Omit<EmbedConfig, "type"> {
161
+ /** Ref to access the handle for programmatic control */
162
+ embedRef?: RefObject<FloatHandle | null>;
163
+ }
164
+ /**
165
+ * Floating bubble widget that expands into a chat window.
166
+ * This is a convenience wrapper around useFloatBubble hook.
167
+ *
168
+ * @example
169
+ * ```tsx
170
+ * <FloatBubble researchId="abc" onSubmit={handleSubmit} />
171
+ * ```
172
+ */
173
+ declare function FloatBubble({ researchId, params, brand, theme, host, onReady, onSubmit, onNavigate, onClose, onError, embedRef, }: FloatBubbleProps): null;
174
+
175
+ export { FloatBubble, type FloatBubbleProps, Fullpage, type FullpageProps, type UseAutoOpenOptions, type UseAutoOpenReturn, type UseFloatBubbleOptions, type UseFloatBubbleReturn, type UsePopupOptions, type UsePopupReturn, type UseSliderOptions, type UseSliderReturn, Widget, type WidgetProps, useAutoOpen, useFloatBubble, usePopup, useSlider, useStableCallback, useThemeSync };
@@ -0,0 +1,175 @@
1
+ import { EmbedConfig, EmbedHandle, FloatHandle, TriggerConfig, ShowOnce } from '@perspective-ai/sdk';
2
+ export { AutoOpenConfig, BrandColors, EmbedConfig, EmbedError, EmbedHandle, FloatHandle, ShowOnce, ThemeValue, TriggerConfig } from '@perspective-ai/sdk';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { HTMLAttributes, RefObject } from 'react';
5
+
6
+ /** Options for usePopup hook */
7
+ interface UsePopupOptions extends Omit<EmbedConfig, "type"> {
8
+ /** Controlled open state */
9
+ open?: boolean;
10
+ /** Callback when open state changes */
11
+ onOpenChange?: (open: boolean) => void;
12
+ }
13
+ /** Return type for usePopup hook */
14
+ interface UsePopupReturn {
15
+ /** Open the popup */
16
+ open: () => void;
17
+ /** Close the popup */
18
+ close: () => void;
19
+ /** Toggle the popup */
20
+ toggle: () => void;
21
+ /** Whether the popup is currently open */
22
+ isOpen: boolean;
23
+ /** The underlying SDK handle (null when closed) */
24
+ handle: EmbedHandle | null;
25
+ }
26
+ /**
27
+ * Headless hook for programmatic popup control.
28
+ * Use this when you need custom trigger elements or programmatic control.
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * // Basic usage with custom trigger
33
+ * const { open, isOpen } = usePopup({ researchId: "abc" });
34
+ * <MyCustomButton onClick={open}>Open Survey</MyCustomButton>
35
+ *
36
+ * // Controlled mode
37
+ * const [isOpen, setIsOpen] = useState(false);
38
+ * const popup = usePopup({
39
+ * researchId: "abc",
40
+ * open: isOpen,
41
+ * onOpenChange: setIsOpen
42
+ * });
43
+ * ```
44
+ */
45
+ declare function usePopup(options: UsePopupOptions): UsePopupReturn;
46
+
47
+ /** Options for useSlider hook */
48
+ interface UseSliderOptions extends Omit<EmbedConfig, "type"> {
49
+ /** Controlled open state */
50
+ open?: boolean;
51
+ /** Callback when open state changes */
52
+ onOpenChange?: (open: boolean) => void;
53
+ }
54
+ /** Return type for useSlider hook */
55
+ interface UseSliderReturn {
56
+ /** Open the slider */
57
+ open: () => void;
58
+ /** Close the slider */
59
+ close: () => void;
60
+ /** Toggle the slider */
61
+ toggle: () => void;
62
+ /** Whether the slider is currently open */
63
+ isOpen: boolean;
64
+ /** The underlying SDK handle (null when closed) */
65
+ handle: EmbedHandle | null;
66
+ }
67
+ /**
68
+ * Headless hook for programmatic slider control.
69
+ * Use this when you need custom trigger elements or programmatic control.
70
+ *
71
+ * @example
72
+ * ```tsx
73
+ * const { open, isOpen } = useSlider({ researchId: "abc" });
74
+ * <MyCustomButton onClick={open}>Give Feedback</MyCustomButton>
75
+ * ```
76
+ */
77
+ declare function useSlider(options: UseSliderOptions): UseSliderReturn;
78
+
79
+ /** Options for useFloatBubble hook */
80
+ interface UseFloatBubbleOptions extends Omit<EmbedConfig, "type"> {
81
+ /** Controlled open state */
82
+ open?: boolean;
83
+ /** Callback when open state changes */
84
+ onOpenChange?: (open: boolean) => void;
85
+ }
86
+ /** Return type for useFloatBubble hook */
87
+ interface UseFloatBubbleReturn {
88
+ /** Open the float bubble window */
89
+ open: () => void;
90
+ /** Close the float bubble window */
91
+ close: () => void;
92
+ /** Toggle the float bubble window */
93
+ toggle: () => void;
94
+ /** Unmount the float bubble entirely */
95
+ unmount: () => void;
96
+ /** Whether the float bubble window is currently open */
97
+ isOpen: boolean;
98
+ /** The underlying SDK handle (null until mounted) */
99
+ handle: FloatHandle | null;
100
+ }
101
+ /**
102
+ * Headless hook for float bubble lifecycle management.
103
+ * Creates a floating bubble button that expands into a chat window.
104
+ * The bubble mounts on component mount and unmounts on component unmount.
105
+ *
106
+ * @example
107
+ * ```tsx
108
+ * // Basic usage - bubble mounts on component mount
109
+ * useFloatBubble({ researchId: "abc" });
110
+ *
111
+ * // With programmatic control
112
+ * const { open, close, isOpen } = useFloatBubble({ researchId: "abc" });
113
+ * <button onClick={open}>Open Chat</button>
114
+ * ```
115
+ */
116
+ declare function useFloatBubble(options: UseFloatBubbleOptions): UseFloatBubbleReturn;
117
+
118
+ interface UseAutoOpenOptions extends Omit<EmbedConfig, "type" | "autoOpen"> {
119
+ trigger: TriggerConfig;
120
+ showOnce?: ShowOnce;
121
+ }
122
+ interface UseAutoOpenReturn {
123
+ /** Cancel the pending trigger */
124
+ cancel: () => void;
125
+ /** Whether the trigger has fired */
126
+ triggered: boolean;
127
+ }
128
+ declare function useAutoOpen(options: UseAutoOpenOptions): UseAutoOpenReturn;
129
+
130
+ type Theme = "light" | "dark";
131
+ type ThemeInput = "light" | "dark" | "system";
132
+ /**
133
+ * Hook to resolve theme based on override and system preference.
134
+ * Listens for system preference changes when theme is "system".
135
+ */
136
+ declare function useThemeSync(theme?: ThemeInput): Theme;
137
+
138
+ declare function useStableCallback<T extends ((...args: any[]) => any) | undefined>(callback: T): T;
139
+
140
+ interface WidgetProps extends Omit<EmbedConfig, "type">, Omit<HTMLAttributes<HTMLDivElement>, "onError" | "onSubmit"> {
141
+ /** Ref to access the embed handle for programmatic control */
142
+ embedRef?: RefObject<EmbedHandle | null>;
143
+ }
144
+ /**
145
+ * Inline widget embed component.
146
+ * Renders the interview directly in a container.
147
+ */
148
+ declare function Widget({ researchId, params, brand, theme, host, onReady, onSubmit, onNavigate, onClose, onError, embedRef, className, style, ...divProps }: WidgetProps): react_jsx_runtime.JSX.Element;
149
+
150
+ interface FullpageProps extends Omit<EmbedConfig, "type"> {
151
+ /** Ref to access the embed handle for programmatic control */
152
+ embedRef?: RefObject<EmbedHandle | null>;
153
+ }
154
+ /**
155
+ * Full viewport embed component.
156
+ * Takes over the entire screen with the interview.
157
+ */
158
+ declare function Fullpage({ researchId, params, brand, theme, host, onReady, onSubmit, onNavigate, onClose, onError, embedRef, }: FullpageProps): null;
159
+
160
+ interface FloatBubbleProps extends Omit<EmbedConfig, "type"> {
161
+ /** Ref to access the handle for programmatic control */
162
+ embedRef?: RefObject<FloatHandle | null>;
163
+ }
164
+ /**
165
+ * Floating bubble widget that expands into a chat window.
166
+ * This is a convenience wrapper around useFloatBubble hook.
167
+ *
168
+ * @example
169
+ * ```tsx
170
+ * <FloatBubble researchId="abc" onSubmit={handleSubmit} />
171
+ * ```
172
+ */
173
+ declare function FloatBubble({ researchId, params, brand, theme, host, onReady, onSubmit, onNavigate, onClose, onError, embedRef, }: FloatBubbleProps): null;
174
+
175
+ export { FloatBubble, type FloatBubbleProps, Fullpage, type FullpageProps, type UseAutoOpenOptions, type UseAutoOpenReturn, type UseFloatBubbleOptions, type UseFloatBubbleReturn, type UsePopupOptions, type UsePopupReturn, type UseSliderOptions, type UseSliderReturn, Widget, type WidgetProps, useAutoOpen, useFloatBubble, usePopup, useSlider, useStableCallback, useThemeSync };