@coxwave/tap-kit 2.0.1 → 2.0.3

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/react.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { TapKitElement, TapKitConfig } from '@coxwave/tap-kit-types';
2
- import React$1 from 'react';
1
+ import { TapKitElement } from '@coxwave/tap-kit-types';
2
+ import React from 'react';
3
3
 
4
4
  /**
5
5
  * React-specific type definitions for TapKit
@@ -66,6 +66,12 @@ interface TapKitControl<T> {
66
66
  * Separated from options for easier event listener management.
67
67
  */
68
68
  handlers: TapKitEventHandlers;
69
+ /**
70
+ * Whether CDN is loaded and Web Component is available
71
+ *
72
+ * @internal Used by TapKit component to delay rendering
73
+ */
74
+ isCdnLoaded: boolean;
69
75
  }
70
76
 
71
77
  /**
@@ -110,24 +116,18 @@ interface TapKitControl<T> {
110
116
  /**
111
117
  * Props for TapKit React component
112
118
  */
113
- interface TapKitProps extends Omit<React$1.HTMLAttributes<TapKitElement>, "children" | "dangerouslySetInnerHTML"> {
119
+ interface TapKitProps extends Omit<React.HTMLAttributes<TapKitElement>, "children" | "dangerouslySetInnerHTML"> {
114
120
  /**
115
121
  * Control object from useTapKit hook
116
122
  *
117
123
  * Provides instance management, configuration, and event handlers.
118
124
  */
119
125
  control: TapKitControl<any>;
120
- /**
121
- * Custom container element ID (optional)
122
- *
123
- * If provided, TapKit will use this element as container.
124
- */
125
- containerId?: string;
126
126
  }
127
127
  declare global {
128
128
  namespace JSX {
129
129
  interface IntrinsicElements {
130
- "tap-kit": React$1.DetailedHTMLProps<React$1.HTMLAttributes<TapKitElement>, TapKitElement> & {
130
+ "tap-kit": React.DetailedHTMLProps<React.HTMLAttributes<TapKitElement>, TapKitElement> & {
131
131
  "api-key"?: string;
132
132
  "user-id"?: string;
133
133
  "course-id"?: string;
@@ -135,7 +135,6 @@ declare global {
135
135
  "clip-play-head"?: number;
136
136
  language?: "ko" | "en";
137
137
  "button-id"?: string;
138
- "container-id"?: string;
139
138
  mode?: "inline" | "floating" | "sidebar";
140
139
  debug?: boolean;
141
140
  "tap-url"?: string;
@@ -158,60 +157,45 @@ declare global {
158
157
  * // tapkitRef.current?.show()
159
158
  * ```
160
159
  */
161
- declare const TapKit: React$1.ForwardRefExoticComponent<TapKitProps & React$1.RefAttributes<TapKitElement>>;
160
+ declare const TapKit: React.ForwardRefExoticComponent<TapKitProps & React.RefAttributes<TapKitElement>>;
162
161
 
163
162
  /**
164
- * useTapKit Hook - Advanced imperative control of TapKit Web Component
165
- *
166
- * This hook provides direct access to the TapKitElement instance and full
167
- * control over its lifecycle. Use this when you need:
168
- * - Direct element manipulation
169
- * - Custom rendering logic
170
- * - Imperative control over Web Component behavior
163
+ * useTapKit Hook - ChatKit-style control for TapKit Web Component
171
164
  *
172
- * For most use cases, prefer the `<TapKit />` component which provides a
173
- * simpler declarative API.
165
+ * This hook provides a control object to manage TapKit through the
166
+ * <TapKit /> component. Inspired by OpenAI's ChatKit pattern.
174
167
  *
175
- * @param options - TapKit configuration
176
- * @returns Object with element reference, state, and control methods
177
- *
178
- * @example Advanced control with custom rendering
168
+ * @example
179
169
  * ```tsx
180
170
  * 'use client';
181
171
  *
182
- * import { useTapKit } from '@coxwave/tap-kit/react';
172
+ * import { TapKit, useTapKit } from '@coxwave/tap-kit/react';
183
173
  *
184
- * function MyComponent() {
185
- * const { element, elementRef, show, hide, isReady, error } = useTapKit({
174
+ * function MyApp() {
175
+ * const tapkit = useTapKit({
186
176
  * apiKey: 'your-key',
187
177
  * userId: 'user-123',
188
178
  * courseId: 'course-456',
189
179
  * clipId: 'clip-789',
180
+ * onReady: () => console.log('Ready!'),
181
+ * onError: (error) => console.error(error),
190
182
  * });
191
183
  *
192
- * // Direct element access for advanced operations
193
- * useEffect(() => {
194
- * if (element) {
195
- * // Direct manipulation of TapKitElement
196
- * console.log('Element mounted:', element);
197
- * }
198
- * }, [element]);
199
- *
200
184
  * return (
201
185
  * <div>
202
- * <button onClick={show} disabled={!isReady}>Show Chat</button>
203
- * <button onClick={hide}>Hide Chat</button>
204
- * {error && <p>Error: {error.message}</p>}
205
- * <div ref={elementRef} /> // Container for Web Component
186
+ * <button onClick={tapkit.show} disabled={!tapkit.isReady}>
187
+ * Ask AI Tutor
188
+ * </button>
189
+ * <TapKit control={tapkit.control} />
206
190
  * </div>
207
191
  * );
208
192
  * }
209
193
  * ```
210
- *
211
- * @see TapKit - Use this component for simpler declarative API
212
194
  */
213
195
 
214
- interface UseTapKitOptions extends TapKitConfig, TapKitEventHandlers {
196
+ interface UseTapKitOptions extends TapKitEventHandlers {
197
+ /** API Key (required) */
198
+ apiKey: string;
215
199
  /** User ID */
216
200
  userId?: string;
217
201
  /** Course ID */
@@ -240,13 +224,7 @@ interface UseTapKitOptions extends TapKitConfig, TapKitEventHandlers {
240
224
  */
241
225
  type TapKitOptions = Omit<UseTapKitOptions, keyof TapKitEventHandlers>;
242
226
  interface UseTapKitReturn {
243
- /** Web Component element reference */
244
- element: TapKitElement | null;
245
- /** Ref object for direct element access */
246
- ref: React.RefObject<TapKitElement | null>;
247
- /** Container ref to attach element */
248
- elementRef: React.RefCallback<HTMLDivElement>;
249
- /** Control object for TapKit component */
227
+ /** Control object for <TapKit /> component */
250
228
  control: TapKitControl<TapKitOptions>;
251
229
  /** Whether TapKit is ready */
252
230
  isReady: boolean;
@@ -263,14 +241,22 @@ interface UseTapKitReturn {
263
241
  userId?: string;
264
242
  clipPlayHead?: number;
265
243
  }) => void;
244
+ /** Video adapter control */
245
+ video: {
246
+ /** Bind video player for timeline synchronization */
247
+ bind: (adapter: {
248
+ getCurrentTime: () => number;
249
+ setCurrentTime: (time: number) => void;
250
+ }, clipId: string) => void;
251
+ /** Unbind current video player */
252
+ unbind: () => void;
253
+ };
266
254
  }
267
255
  /**
268
- * Hook for managing TapKit Web Component
269
- *
270
- * Automatically loads CDN, creates Web Component, and provides control methods.
256
+ * Hook for managing TapKit Web Component (ChatKit Pattern)
271
257
  *
272
- * @param options - TapKit configuration with event handlers
273
- * @returns Methods to control TapKit instance and control object
258
+ * Returns a control object to pass to <TapKit /> component.
259
+ * The component handles rendering, this hook handles state and methods.
274
260
  */
275
261
  declare function useTapKit(options: UseTapKitOptions): UseTapKitReturn;
276
262
 
package/dist/react.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { TapKitElement, TapKitConfig } from '@coxwave/tap-kit-types';
2
- import React$1 from 'react';
1
+ import { TapKitElement } from '@coxwave/tap-kit-types';
2
+ import React from 'react';
3
3
 
4
4
  /**
5
5
  * React-specific type definitions for TapKit
@@ -66,6 +66,12 @@ interface TapKitControl<T> {
66
66
  * Separated from options for easier event listener management.
67
67
  */
68
68
  handlers: TapKitEventHandlers;
69
+ /**
70
+ * Whether CDN is loaded and Web Component is available
71
+ *
72
+ * @internal Used by TapKit component to delay rendering
73
+ */
74
+ isCdnLoaded: boolean;
69
75
  }
70
76
 
71
77
  /**
@@ -110,24 +116,18 @@ interface TapKitControl<T> {
110
116
  /**
111
117
  * Props for TapKit React component
112
118
  */
113
- interface TapKitProps extends Omit<React$1.HTMLAttributes<TapKitElement>, "children" | "dangerouslySetInnerHTML"> {
119
+ interface TapKitProps extends Omit<React.HTMLAttributes<TapKitElement>, "children" | "dangerouslySetInnerHTML"> {
114
120
  /**
115
121
  * Control object from useTapKit hook
116
122
  *
117
123
  * Provides instance management, configuration, and event handlers.
118
124
  */
119
125
  control: TapKitControl<any>;
120
- /**
121
- * Custom container element ID (optional)
122
- *
123
- * If provided, TapKit will use this element as container.
124
- */
125
- containerId?: string;
126
126
  }
127
127
  declare global {
128
128
  namespace JSX {
129
129
  interface IntrinsicElements {
130
- "tap-kit": React$1.DetailedHTMLProps<React$1.HTMLAttributes<TapKitElement>, TapKitElement> & {
130
+ "tap-kit": React.DetailedHTMLProps<React.HTMLAttributes<TapKitElement>, TapKitElement> & {
131
131
  "api-key"?: string;
132
132
  "user-id"?: string;
133
133
  "course-id"?: string;
@@ -135,7 +135,6 @@ declare global {
135
135
  "clip-play-head"?: number;
136
136
  language?: "ko" | "en";
137
137
  "button-id"?: string;
138
- "container-id"?: string;
139
138
  mode?: "inline" | "floating" | "sidebar";
140
139
  debug?: boolean;
141
140
  "tap-url"?: string;
@@ -158,60 +157,45 @@ declare global {
158
157
  * // tapkitRef.current?.show()
159
158
  * ```
160
159
  */
161
- declare const TapKit: React$1.ForwardRefExoticComponent<TapKitProps & React$1.RefAttributes<TapKitElement>>;
160
+ declare const TapKit: React.ForwardRefExoticComponent<TapKitProps & React.RefAttributes<TapKitElement>>;
162
161
 
163
162
  /**
164
- * useTapKit Hook - Advanced imperative control of TapKit Web Component
165
- *
166
- * This hook provides direct access to the TapKitElement instance and full
167
- * control over its lifecycle. Use this when you need:
168
- * - Direct element manipulation
169
- * - Custom rendering logic
170
- * - Imperative control over Web Component behavior
163
+ * useTapKit Hook - ChatKit-style control for TapKit Web Component
171
164
  *
172
- * For most use cases, prefer the `<TapKit />` component which provides a
173
- * simpler declarative API.
165
+ * This hook provides a control object to manage TapKit through the
166
+ * <TapKit /> component. Inspired by OpenAI's ChatKit pattern.
174
167
  *
175
- * @param options - TapKit configuration
176
- * @returns Object with element reference, state, and control methods
177
- *
178
- * @example Advanced control with custom rendering
168
+ * @example
179
169
  * ```tsx
180
170
  * 'use client';
181
171
  *
182
- * import { useTapKit } from '@coxwave/tap-kit/react';
172
+ * import { TapKit, useTapKit } from '@coxwave/tap-kit/react';
183
173
  *
184
- * function MyComponent() {
185
- * const { element, elementRef, show, hide, isReady, error } = useTapKit({
174
+ * function MyApp() {
175
+ * const tapkit = useTapKit({
186
176
  * apiKey: 'your-key',
187
177
  * userId: 'user-123',
188
178
  * courseId: 'course-456',
189
179
  * clipId: 'clip-789',
180
+ * onReady: () => console.log('Ready!'),
181
+ * onError: (error) => console.error(error),
190
182
  * });
191
183
  *
192
- * // Direct element access for advanced operations
193
- * useEffect(() => {
194
- * if (element) {
195
- * // Direct manipulation of TapKitElement
196
- * console.log('Element mounted:', element);
197
- * }
198
- * }, [element]);
199
- *
200
184
  * return (
201
185
  * <div>
202
- * <button onClick={show} disabled={!isReady}>Show Chat</button>
203
- * <button onClick={hide}>Hide Chat</button>
204
- * {error && <p>Error: {error.message}</p>}
205
- * <div ref={elementRef} /> // Container for Web Component
186
+ * <button onClick={tapkit.show} disabled={!tapkit.isReady}>
187
+ * Ask AI Tutor
188
+ * </button>
189
+ * <TapKit control={tapkit.control} />
206
190
  * </div>
207
191
  * );
208
192
  * }
209
193
  * ```
210
- *
211
- * @see TapKit - Use this component for simpler declarative API
212
194
  */
213
195
 
214
- interface UseTapKitOptions extends TapKitConfig, TapKitEventHandlers {
196
+ interface UseTapKitOptions extends TapKitEventHandlers {
197
+ /** API Key (required) */
198
+ apiKey: string;
215
199
  /** User ID */
216
200
  userId?: string;
217
201
  /** Course ID */
@@ -240,13 +224,7 @@ interface UseTapKitOptions extends TapKitConfig, TapKitEventHandlers {
240
224
  */
241
225
  type TapKitOptions = Omit<UseTapKitOptions, keyof TapKitEventHandlers>;
242
226
  interface UseTapKitReturn {
243
- /** Web Component element reference */
244
- element: TapKitElement | null;
245
- /** Ref object for direct element access */
246
- ref: React.RefObject<TapKitElement | null>;
247
- /** Container ref to attach element */
248
- elementRef: React.RefCallback<HTMLDivElement>;
249
- /** Control object for TapKit component */
227
+ /** Control object for <TapKit /> component */
250
228
  control: TapKitControl<TapKitOptions>;
251
229
  /** Whether TapKit is ready */
252
230
  isReady: boolean;
@@ -263,14 +241,22 @@ interface UseTapKitReturn {
263
241
  userId?: string;
264
242
  clipPlayHead?: number;
265
243
  }) => void;
244
+ /** Video adapter control */
245
+ video: {
246
+ /** Bind video player for timeline synchronization */
247
+ bind: (adapter: {
248
+ getCurrentTime: () => number;
249
+ setCurrentTime: (time: number) => void;
250
+ }, clipId: string) => void;
251
+ /** Unbind current video player */
252
+ unbind: () => void;
253
+ };
266
254
  }
267
255
  /**
268
- * Hook for managing TapKit Web Component
269
- *
270
- * Automatically loads CDN, creates Web Component, and provides control methods.
256
+ * Hook for managing TapKit Web Component (ChatKit Pattern)
271
257
  *
272
- * @param options - TapKit configuration with event handlers
273
- * @returns Methods to control TapKit instance and control object
258
+ * Returns a control object to pass to <TapKit /> component.
259
+ * The component handles rendering, this hook handles state and methods.
274
260
  */
275
261
  declare function useTapKit(options: UseTapKitOptions): UseTapKitReturn;
276
262