@demokit-ai/react 0.2.0 → 0.3.0
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/LICENSE +190 -0
- package/dist/index.cjs +507 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +255 -10
- package/dist/index.d.ts +255 -10
- package/dist/index.js +462 -52
- package/dist/index.js.map +1 -1
- package/package.json +14 -30
- package/README.md +0 -132
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,40 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as _demokit_ai_core from '@demokit-ai/core';
|
|
3
|
-
import { FixtureMap, SessionState } from '@demokit-ai/core';
|
|
3
|
+
import { FixtureMap, CloudFixtureResponse, SessionState } from '@demokit-ai/core';
|
|
4
4
|
export { FixtureHandler, FixtureMap, RequestContext, SessionState } from '@demokit-ai/core';
|
|
5
5
|
import * as react from 'react';
|
|
6
|
-
import { ReactNode } from 'react';
|
|
6
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Props for the DemoKitProvider component
|
|
10
|
+
*
|
|
11
|
+
* The provider supports two modes:
|
|
12
|
+
* 1. **Local mode**: Provide `fixtures` prop with pattern handlers
|
|
13
|
+
* 2. **Remote mode**: Provide `apiKey` to fetch from DemoKit Cloud
|
|
14
|
+
*
|
|
15
|
+
* @example Local mode
|
|
16
|
+
* ```tsx
|
|
17
|
+
* <DemoKitProvider fixtures={{ 'GET /api/users': () => [] }}>
|
|
18
|
+
* <App />
|
|
19
|
+
* </DemoKitProvider>
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example Remote mode (zero-config)
|
|
23
|
+
* ```tsx
|
|
24
|
+
* <DemoKitProvider apiKey="dk_live_xxx">
|
|
25
|
+
* <App />
|
|
26
|
+
* </DemoKitProvider>
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example Remote mode with local overrides
|
|
30
|
+
* ```tsx
|
|
31
|
+
* <DemoKitProvider
|
|
32
|
+
* apiKey="dk_live_xxx"
|
|
33
|
+
* fixtures={{ 'POST /api/users': ({ body }) => ({ id: 'custom', ...body }) }}
|
|
34
|
+
* >
|
|
35
|
+
* <App />
|
|
36
|
+
* </DemoKitProvider>
|
|
37
|
+
* ```
|
|
10
38
|
*/
|
|
11
39
|
interface DemoKitProviderProps {
|
|
12
40
|
/**
|
|
@@ -14,9 +42,56 @@ interface DemoKitProviderProps {
|
|
|
14
42
|
*/
|
|
15
43
|
children: ReactNode;
|
|
16
44
|
/**
|
|
17
|
-
* Map of URL patterns to fixture handlers
|
|
45
|
+
* Map of URL patterns to fixture handlers (local mode)
|
|
46
|
+
* In remote mode, these act as overrides for cloud fixtures
|
|
47
|
+
*/
|
|
48
|
+
fixtures?: FixtureMap;
|
|
49
|
+
/**
|
|
50
|
+
* DemoKit Cloud API key for remote mode
|
|
51
|
+
* Format: dk_live_xxxx
|
|
52
|
+
*
|
|
53
|
+
* When provided, fixtures are fetched from DemoKit Cloud.
|
|
54
|
+
* Any `fixtures` prop values will override the cloud fixtures.
|
|
55
|
+
*/
|
|
56
|
+
apiKey?: string;
|
|
57
|
+
/**
|
|
58
|
+
* DemoKit Cloud API URL
|
|
59
|
+
* @default 'https://api.demokit.cloud'
|
|
60
|
+
*/
|
|
61
|
+
cloudUrl?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Timeout for cloud API requests in milliseconds
|
|
64
|
+
* @default 10000
|
|
65
|
+
*/
|
|
66
|
+
timeout?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Whether to retry on fetch failure
|
|
69
|
+
* @default true
|
|
70
|
+
*/
|
|
71
|
+
retry?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Maximum number of retries for cloud fetch
|
|
74
|
+
* @default 3
|
|
75
|
+
*/
|
|
76
|
+
maxRetries?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Callback when remote fixtures are successfully loaded
|
|
18
79
|
*/
|
|
19
|
-
|
|
80
|
+
onRemoteLoad?: (response: CloudFixtureResponse) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Callback when remote fetch fails
|
|
83
|
+
*/
|
|
84
|
+
onRemoteError?: (error: Error) => void;
|
|
85
|
+
/**
|
|
86
|
+
* Content to render while loading remote fixtures
|
|
87
|
+
* @default null (renders nothing while loading)
|
|
88
|
+
*/
|
|
89
|
+
loadingFallback?: ReactNode;
|
|
90
|
+
/**
|
|
91
|
+
* Content to render when remote fetch fails
|
|
92
|
+
* If not provided, children are rendered (with local fixtures only if provided)
|
|
93
|
+
*/
|
|
94
|
+
errorFallback?: ReactNode | ((error: Error) => ReactNode);
|
|
20
95
|
/**
|
|
21
96
|
* localStorage key for persisting demo mode state
|
|
22
97
|
* @default 'demokit-mode'
|
|
@@ -51,6 +126,21 @@ interface DemoModeContextValue {
|
|
|
51
126
|
* Always check this before rendering demo-dependent UI
|
|
52
127
|
*/
|
|
53
128
|
isHydrated: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Whether remote fixtures are currently being loaded
|
|
131
|
+
* Only relevant when apiKey is provided
|
|
132
|
+
*/
|
|
133
|
+
isLoading: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Error that occurred during remote fetch
|
|
136
|
+
* Only set when apiKey is provided and fetch fails
|
|
137
|
+
*/
|
|
138
|
+
remoteError: Error | null;
|
|
139
|
+
/**
|
|
140
|
+
* Version identifier from the loaded cloud fixtures
|
|
141
|
+
* Useful for cache invalidation and debugging
|
|
142
|
+
*/
|
|
143
|
+
remoteVersion: string | null;
|
|
54
144
|
/**
|
|
55
145
|
* Enable demo mode
|
|
56
146
|
*/
|
|
@@ -78,6 +168,12 @@ interface DemoModeContextValue {
|
|
|
78
168
|
* Returns null if the interceptor hasn't been initialized yet
|
|
79
169
|
*/
|
|
80
170
|
getSession(): SessionState | null;
|
|
171
|
+
/**
|
|
172
|
+
* Refetch fixtures from DemoKit Cloud
|
|
173
|
+
* Only works when apiKey is provided
|
|
174
|
+
* Returns a promise that resolves when the fetch completes
|
|
175
|
+
*/
|
|
176
|
+
refetch(): Promise<void>;
|
|
81
177
|
}
|
|
82
178
|
/**
|
|
83
179
|
* Props for the DemoModeBanner component
|
|
@@ -107,6 +203,18 @@ interface DemoModeBannerProps {
|
|
|
107
203
|
* @default true
|
|
108
204
|
*/
|
|
109
205
|
showIcon?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Show "Powered by DemoKit" branding
|
|
208
|
+
* Note: For OSS users, this is always true regardless of the prop value.
|
|
209
|
+
* Only paid DemoKit Cloud users can hide the branding.
|
|
210
|
+
* @default true
|
|
211
|
+
*/
|
|
212
|
+
showPoweredBy?: boolean;
|
|
213
|
+
/**
|
|
214
|
+
* URL for the "Powered by" link
|
|
215
|
+
* @default 'https://demokit.ai'
|
|
216
|
+
*/
|
|
217
|
+
poweredByUrl?: string;
|
|
110
218
|
/**
|
|
111
219
|
* Custom styles for the banner container
|
|
112
220
|
*/
|
|
@@ -124,7 +232,12 @@ interface DemoModeBannerProps {
|
|
|
124
232
|
* Wraps your app to provide demo mode state and controls.
|
|
125
233
|
* Handles SSR hydration safely and persists state to localStorage.
|
|
126
234
|
*
|
|
127
|
-
*
|
|
235
|
+
* Supports two modes:
|
|
236
|
+
* 1. **Local mode**: Pass `fixtures` prop with pattern handlers
|
|
237
|
+
* 2. **Remote mode**: Pass `apiKey` to fetch from DemoKit Cloud
|
|
238
|
+
*
|
|
239
|
+
* @example Local mode
|
|
240
|
+
* ```tsx
|
|
128
241
|
* const fixtures = {
|
|
129
242
|
* 'GET /api/users': () => [{ id: '1', name: 'Demo User' }],
|
|
130
243
|
* 'GET /api/users/:id': ({ params }) => ({ id: params.id, name: 'Demo User' }),
|
|
@@ -132,16 +245,28 @@ interface DemoModeBannerProps {
|
|
|
132
245
|
*
|
|
133
246
|
* function App() {
|
|
134
247
|
* return (
|
|
248
|
+
* <DemoKitProvider fixtures={fixtures}>
|
|
249
|
+
* <YourApp />
|
|
250
|
+
* </DemoKitProvider>
|
|
251
|
+
* )
|
|
252
|
+
* }
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* @example Remote mode (zero-config)
|
|
256
|
+
* ```tsx
|
|
257
|
+
* function App() {
|
|
258
|
+
* return (
|
|
135
259
|
* <DemoKitProvider
|
|
136
|
-
*
|
|
137
|
-
*
|
|
260
|
+
* apiKey="dk_live_xxx"
|
|
261
|
+
* loadingFallback={<LoadingSpinner />}
|
|
138
262
|
* >
|
|
139
263
|
* <YourApp />
|
|
140
264
|
* </DemoKitProvider>
|
|
141
265
|
* )
|
|
142
266
|
* }
|
|
267
|
+
* ```
|
|
143
268
|
*/
|
|
144
|
-
declare function DemoKitProvider({ children, fixtures, storageKey, initialEnabled, onDemoModeChange, baseUrl, }: DemoKitProviderProps): react_jsx_runtime.JSX.Element;
|
|
269
|
+
declare function DemoKitProvider({ children, fixtures, apiKey, cloudUrl, timeout, retry, maxRetries, onRemoteLoad, onRemoteError, loadingFallback, errorFallback, storageKey, initialEnabled, onDemoModeChange, baseUrl, }: DemoKitProviderProps): react_jsx_runtime.JSX.Element;
|
|
145
270
|
|
|
146
271
|
/**
|
|
147
272
|
* Hook to access demo mode state and controls
|
|
@@ -224,7 +349,127 @@ declare function useDemoSession(): _demokit_ai_core.SessionState | null;
|
|
|
224
349
|
* exitLabel="Exit Preview"
|
|
225
350
|
* />
|
|
226
351
|
*/
|
|
227
|
-
declare function DemoModeBanner({ className, exitLabel, demoLabel, description, showIcon, style, onExit, }: DemoModeBannerProps): react_jsx_runtime.JSX.Element | null;
|
|
352
|
+
declare function DemoModeBanner({ className, exitLabel, demoLabel, description, showIcon, showPoweredBy, poweredByUrl, style, onExit, }: DemoModeBannerProps): react_jsx_runtime.JSX.Element | null;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Props for the DemoModeToggle component
|
|
356
|
+
*/
|
|
357
|
+
interface DemoModeToggleProps {
|
|
358
|
+
/**
|
|
359
|
+
* Show "Demo Mode" label next to the toggle
|
|
360
|
+
* @default true
|
|
361
|
+
*/
|
|
362
|
+
showLabel?: boolean;
|
|
363
|
+
/**
|
|
364
|
+
* Label text to display
|
|
365
|
+
* @default 'Demo Mode'
|
|
366
|
+
*/
|
|
367
|
+
label?: string;
|
|
368
|
+
/**
|
|
369
|
+
* Show "Powered by DemoKit" branding
|
|
370
|
+
* Note: For OSS users, this is always true regardless of the prop value.
|
|
371
|
+
* Only paid DemoKit Cloud users can hide the branding.
|
|
372
|
+
* @default true
|
|
373
|
+
*/
|
|
374
|
+
showPoweredBy?: boolean;
|
|
375
|
+
/**
|
|
376
|
+
* URL for the "Powered by" link
|
|
377
|
+
* @default 'https://demokit.ai'
|
|
378
|
+
*/
|
|
379
|
+
poweredByUrl?: string;
|
|
380
|
+
/**
|
|
381
|
+
* Position of the toggle
|
|
382
|
+
* - 'inline': Renders where placed in the component tree
|
|
383
|
+
* - 'floating': Fixed position, can be moved around
|
|
384
|
+
* - 'corner': Fixed to bottom-right corner
|
|
385
|
+
* @default 'inline'
|
|
386
|
+
*/
|
|
387
|
+
position?: 'inline' | 'floating' | 'corner';
|
|
388
|
+
/**
|
|
389
|
+
* Size of the toggle
|
|
390
|
+
* @default 'md'
|
|
391
|
+
*/
|
|
392
|
+
size?: 'sm' | 'md' | 'lg';
|
|
393
|
+
/**
|
|
394
|
+
* Additional CSS class name
|
|
395
|
+
*/
|
|
396
|
+
className?: string;
|
|
397
|
+
/**
|
|
398
|
+
* Custom styles
|
|
399
|
+
*/
|
|
400
|
+
style?: CSSProperties;
|
|
401
|
+
/**
|
|
402
|
+
* Callback when toggle state changes
|
|
403
|
+
*/
|
|
404
|
+
onChange?: (enabled: boolean) => void;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* A toggle switch component for enabling/disabling demo mode
|
|
408
|
+
*
|
|
409
|
+
* Supports inline placement or fixed positioning (floating/corner).
|
|
410
|
+
* Includes optional "Powered by DemoKit" branding that is always shown for OSS users.
|
|
411
|
+
*
|
|
412
|
+
* @example Basic inline usage
|
|
413
|
+
* <DemoModeToggle />
|
|
414
|
+
*
|
|
415
|
+
* @example Corner position (floating)
|
|
416
|
+
* <DemoModeToggle position="corner" />
|
|
417
|
+
*
|
|
418
|
+
* @example Without label
|
|
419
|
+
* <DemoModeToggle showLabel={false} />
|
|
420
|
+
*
|
|
421
|
+
* @example With custom label and callback
|
|
422
|
+
* <DemoModeToggle
|
|
423
|
+
* label="Preview Mode"
|
|
424
|
+
* onChange={(enabled) => console.log('Demo mode:', enabled)}
|
|
425
|
+
* />
|
|
426
|
+
*/
|
|
427
|
+
declare function DemoModeToggle({ showLabel, label, showPoweredBy, poweredByUrl, position, size, className, style, onChange, }: DemoModeToggleProps): react_jsx_runtime.JSX.Element | null;
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Props for the PoweredByBadge component
|
|
431
|
+
*/
|
|
432
|
+
interface PoweredByBadgeProps {
|
|
433
|
+
/**
|
|
434
|
+
* URL to link to when clicked
|
|
435
|
+
* @default 'https://demokit.ai'
|
|
436
|
+
*/
|
|
437
|
+
url?: string;
|
|
438
|
+
/**
|
|
439
|
+
* Visual variant for light/dark backgrounds
|
|
440
|
+
* @default 'auto'
|
|
441
|
+
*/
|
|
442
|
+
variant?: 'light' | 'dark' | 'auto';
|
|
443
|
+
/**
|
|
444
|
+
* Size of the badge
|
|
445
|
+
* @default 'sm'
|
|
446
|
+
*/
|
|
447
|
+
size?: 'xs' | 'sm' | 'md';
|
|
448
|
+
/**
|
|
449
|
+
* Additional CSS class name
|
|
450
|
+
*/
|
|
451
|
+
className?: string;
|
|
452
|
+
/**
|
|
453
|
+
* Custom styles
|
|
454
|
+
*/
|
|
455
|
+
style?: CSSProperties;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* A "Powered by DemoKit" badge that links to demokit.ai
|
|
459
|
+
*
|
|
460
|
+
* This badge is shown by default for OSS users and cannot be hidden
|
|
461
|
+
* without a valid DemoKit Cloud paid plan.
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* <PoweredByBadge />
|
|
465
|
+
*
|
|
466
|
+
* @example With dark theme
|
|
467
|
+
* <PoweredByBadge variant="dark" />
|
|
468
|
+
*
|
|
469
|
+
* @example Small size
|
|
470
|
+
* <PoweredByBadge size="xs" />
|
|
471
|
+
*/
|
|
472
|
+
declare function PoweredByBadge({ url, variant, size, className, style, }: PoweredByBadgeProps): react_jsx_runtime.JSX.Element;
|
|
228
473
|
|
|
229
474
|
/**
|
|
230
475
|
* React context for demo mode state
|
|
@@ -232,4 +477,4 @@ declare function DemoModeBanner({ className, exitLabel, demoLabel, description,
|
|
|
232
477
|
*/
|
|
233
478
|
declare const DemoModeContext: react.Context<DemoModeContextValue | undefined>;
|
|
234
479
|
|
|
235
|
-
export { DemoKitProvider, type DemoKitProviderProps, DemoModeBanner, type DemoModeBannerProps, DemoModeContext, type DemoModeContextValue, useDemoMode, useDemoSession, useIsDemoMode, useIsHydrated };
|
|
480
|
+
export { DemoKitProvider, type DemoKitProviderProps, DemoModeBanner, type DemoModeBannerProps, DemoModeContext, type DemoModeContextValue, DemoModeToggle, type DemoModeToggleProps, PoweredByBadge, type PoweredByBadgeProps, useDemoMode, useDemoSession, useIsDemoMode, useIsHydrated };
|