@coxwave/tap-kit 1.0.6 โ 2.0.1
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/README.md +178 -76
- package/dist/index.d.cts +36 -8
- package/dist/index.d.ts +36 -8
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.cts +249 -59
- package/dist/react.d.ts +249 -59
- package/dist/react.js +2 -382
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +2 -380
- package/dist/react.mjs.map +1 -1
- package/package.json +7 -6
package/dist/react.d.ts
CHANGED
|
@@ -1,87 +1,277 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TapKitElement, TapKitConfig } from '@coxwave/tap-kit-types';
|
|
2
|
+
import React$1 from 'react';
|
|
2
3
|
|
|
3
|
-
interface UseTapKitReturn {
|
|
4
|
-
/** TapKit instance */
|
|
5
|
-
kit: TapKitInstance | null;
|
|
6
|
-
/** Whether TapKit is ready to use */
|
|
7
|
-
isReady: boolean;
|
|
8
|
-
/** Error that occurred during loading */
|
|
9
|
-
error: Error | null;
|
|
10
|
-
/** Setup TapKit with given parameters (button, course info, etc.) */
|
|
11
|
-
setup: (params: TapKitInitParams) => Promise<() => void>;
|
|
12
|
-
}
|
|
13
4
|
/**
|
|
14
|
-
*
|
|
5
|
+
* React-specific type definitions for TapKit
|
|
15
6
|
*
|
|
16
|
-
*
|
|
17
|
-
|
|
7
|
+
* Defines event handler types and control patterns for React integration.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Event handler type definitions for TapKit Web Component
|
|
18
12
|
*
|
|
19
|
-
*
|
|
20
|
-
|
|
13
|
+
* Maps CustomEvent types to React callback signatures.
|
|
14
|
+
*/
|
|
15
|
+
interface TapKitEventHandlers {
|
|
16
|
+
/**
|
|
17
|
+
* Called when TapKit SDK is ready
|
|
18
|
+
* @example onReady={() => console.log('TapKit ready!')}
|
|
19
|
+
*/
|
|
20
|
+
onReady?: () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Called when initialization or runtime error occurs
|
|
23
|
+
* @example onError={(error) => console.error('TapKit error:', error)}
|
|
24
|
+
*/
|
|
25
|
+
onError?: (error: Error) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Called when timeline seek event occurs
|
|
28
|
+
* @example onTimelineSeek={(clipPlayHead, clipId) => console.log('Seek:', clipPlayHead)}
|
|
29
|
+
*/
|
|
30
|
+
onTimelineSeek?: (clipPlayHead: number, clipId: string) => void;
|
|
31
|
+
/**
|
|
32
|
+
* Called when alarm fade-in occurs
|
|
33
|
+
* @example onAlarmFadeIn={(messageInfo) => console.log('Alarm:', messageInfo)}
|
|
34
|
+
*/
|
|
35
|
+
onAlarmFadeIn?: (messageInfo: unknown) => void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Control object pattern for managing TapKit instance
|
|
21
39
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
40
|
+
* Separates instance management (setInstance) from configuration (options)
|
|
41
|
+
* and event handling (handlers). Inspired by ChatKit's control pattern.
|
|
24
42
|
*
|
|
25
43
|
* @example
|
|
26
44
|
* ```tsx
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
|
|
45
|
+
* const tapkit = useTapKit({ apiKey: 'key', onReady: () => {} });
|
|
46
|
+
* <TapKit control={tapkit.control} />
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
interface TapKitControl<T> {
|
|
50
|
+
/**
|
|
51
|
+
* Set the TapKit element instance reference
|
|
52
|
+
*
|
|
53
|
+
* Called by TapKit component to register the element instance.
|
|
54
|
+
* Enables imperative control via useTapKit methods.
|
|
55
|
+
*/
|
|
56
|
+
setInstance: (instance: TapKitElement | null) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Configuration options (non-function values)
|
|
59
|
+
*
|
|
60
|
+
* All options except event handlers.
|
|
61
|
+
*/
|
|
62
|
+
options: T;
|
|
63
|
+
/**
|
|
64
|
+
* Event handler callbacks (function values)
|
|
65
|
+
*
|
|
66
|
+
* Separated from options for easier event listener management.
|
|
67
|
+
*/
|
|
68
|
+
handlers: TapKitEventHandlers;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* TapKit React Component
|
|
31
73
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* apiKey: 'your-api-key',
|
|
35
|
-
* });
|
|
74
|
+
* Declarative React wrapper for <tap-kit> Web Component.
|
|
75
|
+
* Use this with useTapKit hook for a clean separation of control and rendering.
|
|
36
76
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* buttonId: 'tap-button',
|
|
41
|
-
* course: {
|
|
42
|
-
* userId: 'user-123',
|
|
43
|
-
* courseId: 'course-456',
|
|
44
|
-
* clipId: 'clip-789',
|
|
45
|
-
* },
|
|
46
|
-
* });
|
|
47
|
-
* }
|
|
48
|
-
* }, [isReady, setup]);
|
|
77
|
+
* @example
|
|
78
|
+
* ```tsx
|
|
79
|
+
* 'use client';
|
|
49
80
|
*
|
|
50
|
-
*
|
|
51
|
-
* return <div>์๋ฌ ๋ฐ์: {error.message}</div>;
|
|
52
|
-
* }
|
|
81
|
+
* import { TapKit, useTapKit } from '@coxwave/tap-kit/react';
|
|
53
82
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
83
|
+
* function MyApp() {
|
|
84
|
+
* const tapkit = useTapKit({
|
|
85
|
+
* apiKey: 'your-key',
|
|
86
|
+
* userId: 'user-123',
|
|
87
|
+
* courseId: 'course-456',
|
|
88
|
+
* clipId: 'clip-789',
|
|
89
|
+
* onReady: () => console.log('TapKit ready!'),
|
|
90
|
+
* onError: (error) => console.error('Error:', error),
|
|
91
|
+
* });
|
|
57
92
|
*
|
|
58
|
-
* return
|
|
93
|
+
* return (
|
|
94
|
+
* <div>
|
|
95
|
+
* <button onClick={tapkit.show} disabled={!tapkit.isReady}>
|
|
96
|
+
* Show Chat
|
|
97
|
+
* </button>
|
|
98
|
+
* <TapKit control={tapkit.control} style={{ height: '600px' }} />
|
|
99
|
+
* </div>
|
|
100
|
+
* );
|
|
59
101
|
* }
|
|
60
102
|
* ```
|
|
61
|
-
*/
|
|
62
|
-
declare function useTapKit(config: TapKitConfig): UseTapKitReturn;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* TapKit React Integration
|
|
66
|
-
*
|
|
67
|
-
* React ์ฑ์์ TapKit์ ์ฝ๊ฒ ์ฌ์ฉํ ์ ์๋ Hook์ ์ ๊ณตํฉ๋๋ค.
|
|
68
|
-
*
|
|
69
|
-
* useTapKit์ useSyncExternalStore๋ฅผ ํ์ฉํ์ฌ ์ ์ญ store๋ฅผ ๊ด๋ฆฌํฉ๋๋ค.
|
|
70
|
-
* ๊ฐ์ apiKey๋ก ์ฌ๋ฌ ์ปดํฌ๋ํธ์์ ํธ์ถํ๋ฉด ์๋์ผ๋ก ๊ฐ์ ์ธ์คํด์ค๋ฅผ ๊ณต์ ํฉ๋๋ค.
|
|
71
103
|
*
|
|
72
104
|
* **Note for Next.js App Router users:**
|
|
73
|
-
*
|
|
74
|
-
* make sure to add 'use client' at the top of your component file that imports this hook.
|
|
105
|
+
* Make sure to add 'use client' at the top of your component file.
|
|
75
106
|
*
|
|
76
107
|
* @see https://edutap-ai-docs.vercel.app/docs/guides/react
|
|
77
108
|
*/
|
|
78
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Props for TapKit React component
|
|
112
|
+
*/
|
|
113
|
+
interface TapKitProps extends Omit<React$1.HTMLAttributes<TapKitElement>, "children" | "dangerouslySetInnerHTML"> {
|
|
114
|
+
/**
|
|
115
|
+
* Control object from useTapKit hook
|
|
116
|
+
*
|
|
117
|
+
* Provides instance management, configuration, and event handlers.
|
|
118
|
+
*/
|
|
119
|
+
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
|
+
}
|
|
79
127
|
declare global {
|
|
80
128
|
namespace JSX {
|
|
81
129
|
interface IntrinsicElements {
|
|
82
|
-
"tap-
|
|
130
|
+
"tap-kit": React$1.DetailedHTMLProps<React$1.HTMLAttributes<TapKitElement>, TapKitElement> & {
|
|
131
|
+
"api-key"?: string;
|
|
132
|
+
"user-id"?: string;
|
|
133
|
+
"course-id"?: string;
|
|
134
|
+
"clip-id"?: string;
|
|
135
|
+
"clip-play-head"?: number;
|
|
136
|
+
language?: "ko" | "en";
|
|
137
|
+
"button-id"?: string;
|
|
138
|
+
"container-id"?: string;
|
|
139
|
+
mode?: "inline" | "floating" | "sidebar";
|
|
140
|
+
debug?: boolean;
|
|
141
|
+
"tap-url"?: string;
|
|
142
|
+
"api-url"?: string;
|
|
143
|
+
environment?: "dev" | "prod" | "staging" | "demo";
|
|
144
|
+
};
|
|
83
145
|
}
|
|
84
146
|
}
|
|
85
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* TapKit React Component
|
|
150
|
+
*
|
|
151
|
+
* Renders <tap-kit> Web Component with React integration.
|
|
152
|
+
* Automatically manages instance lifecycle and event listeners.
|
|
153
|
+
*
|
|
154
|
+
* **Ref Access**: The forwarded ref provides direct access to the TapKitElement:
|
|
155
|
+
* ```tsx
|
|
156
|
+
* const tapkitRef = useRef<TapKitElement>(null);
|
|
157
|
+
* <TapKit ref={tapkitRef} control={...} />
|
|
158
|
+
* // tapkitRef.current?.show()
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
declare const TapKit: React$1.ForwardRefExoticComponent<TapKitProps & React$1.RefAttributes<TapKitElement>>;
|
|
162
|
+
|
|
163
|
+
/**
|
|
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
|
|
171
|
+
*
|
|
172
|
+
* For most use cases, prefer the `<TapKit />` component which provides a
|
|
173
|
+
* simpler declarative API.
|
|
174
|
+
*
|
|
175
|
+
* @param options - TapKit configuration
|
|
176
|
+
* @returns Object with element reference, state, and control methods
|
|
177
|
+
*
|
|
178
|
+
* @example Advanced control with custom rendering
|
|
179
|
+
* ```tsx
|
|
180
|
+
* 'use client';
|
|
181
|
+
*
|
|
182
|
+
* import { useTapKit } from '@coxwave/tap-kit/react';
|
|
183
|
+
*
|
|
184
|
+
* function MyComponent() {
|
|
185
|
+
* const { element, elementRef, show, hide, isReady, error } = useTapKit({
|
|
186
|
+
* apiKey: 'your-key',
|
|
187
|
+
* userId: 'user-123',
|
|
188
|
+
* courseId: 'course-456',
|
|
189
|
+
* clipId: 'clip-789',
|
|
190
|
+
* });
|
|
191
|
+
*
|
|
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
|
+
* return (
|
|
201
|
+
* <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
|
|
206
|
+
* </div>
|
|
207
|
+
* );
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @see TapKit - Use this component for simpler declarative API
|
|
212
|
+
*/
|
|
213
|
+
|
|
214
|
+
interface UseTapKitOptions extends TapKitConfig, TapKitEventHandlers {
|
|
215
|
+
/** User ID */
|
|
216
|
+
userId?: string;
|
|
217
|
+
/** Course ID */
|
|
218
|
+
courseId?: string;
|
|
219
|
+
/** Clip ID */
|
|
220
|
+
clipId?: string;
|
|
221
|
+
/** Clip playhead position */
|
|
222
|
+
clipPlayHead?: number;
|
|
223
|
+
/** Language */
|
|
224
|
+
language?: "ko" | "en";
|
|
225
|
+
/** Custom button element ID */
|
|
226
|
+
buttonId?: string;
|
|
227
|
+
/** Display mode */
|
|
228
|
+
mode?: "inline" | "floating" | "sidebar";
|
|
229
|
+
/** Debug mode */
|
|
230
|
+
debug?: boolean;
|
|
231
|
+
/** TAP Frontend URL */
|
|
232
|
+
tapUrl?: string;
|
|
233
|
+
/** API Backend URL */
|
|
234
|
+
apiUrl?: string;
|
|
235
|
+
/** Environment */
|
|
236
|
+
environment?: "dev" | "prod" | "staging" | "demo";
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Configuration options type (non-function values)
|
|
240
|
+
*/
|
|
241
|
+
type TapKitOptions = Omit<UseTapKitOptions, keyof TapKitEventHandlers>;
|
|
242
|
+
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 */
|
|
250
|
+
control: TapKitControl<TapKitOptions>;
|
|
251
|
+
/** Whether TapKit is ready */
|
|
252
|
+
isReady: boolean;
|
|
253
|
+
/** Error during initialization */
|
|
254
|
+
error: Error | null;
|
|
255
|
+
/** Show chat interface */
|
|
256
|
+
show: () => void;
|
|
257
|
+
/** Hide chat interface */
|
|
258
|
+
hide: () => void;
|
|
259
|
+
/** Set course information */
|
|
260
|
+
setCourse: (course: {
|
|
261
|
+
courseId: string;
|
|
262
|
+
clipId: string;
|
|
263
|
+
userId?: string;
|
|
264
|
+
clipPlayHead?: number;
|
|
265
|
+
}) => void;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Hook for managing TapKit Web Component
|
|
269
|
+
*
|
|
270
|
+
* Automatically loads CDN, creates Web Component, and provides control methods.
|
|
271
|
+
*
|
|
272
|
+
* @param options - TapKit configuration with event handlers
|
|
273
|
+
* @returns Methods to control TapKit instance and control object
|
|
274
|
+
*/
|
|
275
|
+
declare function useTapKit(options: UseTapKitOptions): UseTapKitReturn;
|
|
86
276
|
|
|
87
|
-
export { type UseTapKitReturn, useTapKit };
|
|
277
|
+
export { TapKit, type TapKitControl, type TapKitEventHandlers, type TapKitProps, type UseTapKitOptions, type UseTapKitReturn, useTapKit };
|