@demokit-ai/react 0.3.0 → 0.4.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/dist/index.d.cts DELETED
@@ -1,480 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as _demokit_ai_core from '@demokit-ai/core';
3
- import { FixtureMap, CloudFixtureResponse, SessionState } from '@demokit-ai/core';
4
- export { FixtureHandler, FixtureMap, RequestContext, SessionState } from '@demokit-ai/core';
5
- import * as react from 'react';
6
- import { ReactNode, CSSProperties } from 'react';
7
-
8
- /**
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
- * ```
38
- */
39
- interface DemoKitProviderProps {
40
- /**
41
- * Child components to render
42
- */
43
- children: ReactNode;
44
- /**
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
79
- */
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);
95
- /**
96
- * localStorage key for persisting demo mode state
97
- * @default 'demokit-mode'
98
- */
99
- storageKey?: string;
100
- /**
101
- * Whether demo mode should be initially enabled
102
- * If not provided, will read from localStorage
103
- * @default false
104
- */
105
- initialEnabled?: boolean;
106
- /**
107
- * Callback invoked when demo mode state changes
108
- */
109
- onDemoModeChange?: (enabled: boolean) => void;
110
- /**
111
- * Base URL to use for relative URL parsing
112
- * @default 'http://localhost'
113
- */
114
- baseUrl?: string;
115
- }
116
- /**
117
- * Value provided by the DemoMode context
118
- */
119
- interface DemoModeContextValue {
120
- /**
121
- * Whether demo mode is currently enabled
122
- */
123
- isDemoMode: boolean;
124
- /**
125
- * Whether the component has hydrated (for SSR safety)
126
- * Always check this before rendering demo-dependent UI
127
- */
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;
144
- /**
145
- * Enable demo mode
146
- */
147
- enable(): void;
148
- /**
149
- * Disable demo mode
150
- */
151
- disable(): void;
152
- /**
153
- * Toggle demo mode and return the new state
154
- */
155
- toggle(): void;
156
- /**
157
- * Set demo mode to a specific state
158
- */
159
- setDemoMode(enabled: boolean): void;
160
- /**
161
- * Reset the session state, clearing all stored data
162
- * Call this to manually reset the demo session without page refresh
163
- */
164
- resetSession(): void;
165
- /**
166
- * Get the current session state instance
167
- * Useful for inspecting or manipulating session state directly
168
- * Returns null if the interceptor hasn't been initialized yet
169
- */
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>;
177
- }
178
- /**
179
- * Props for the DemoModeBanner component
180
- */
181
- interface DemoModeBannerProps {
182
- /**
183
- * Additional CSS class name
184
- */
185
- className?: string;
186
- /**
187
- * Label for the exit button
188
- * @default 'Exit Demo Mode'
189
- */
190
- exitLabel?: string;
191
- /**
192
- * Label shown when demo mode is active
193
- * @default 'Demo Mode Active'
194
- */
195
- demoLabel?: string;
196
- /**
197
- * Description shown in the banner
198
- * @default 'Changes are simulated and not saved'
199
- */
200
- description?: string;
201
- /**
202
- * Whether to show the eye icon
203
- * @default true
204
- */
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;
218
- /**
219
- * Custom styles for the banner container
220
- */
221
- style?: React.CSSProperties;
222
- /**
223
- * Callback when exit button is clicked
224
- * If not provided, will call disable() from context
225
- */
226
- onExit?: () => void;
227
- }
228
-
229
- /**
230
- * Provider component that enables demo mode functionality
231
- *
232
- * Wraps your app to provide demo mode state and controls.
233
- * Handles SSR hydration safely and persists state to localStorage.
234
- *
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
241
- * const fixtures = {
242
- * 'GET /api/users': () => [{ id: '1', name: 'Demo User' }],
243
- * 'GET /api/users/:id': ({ params }) => ({ id: params.id, name: 'Demo User' }),
244
- * }
245
- *
246
- * function App() {
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 (
259
- * <DemoKitProvider
260
- * apiKey="dk_live_xxx"
261
- * loadingFallback={<LoadingSpinner />}
262
- * >
263
- * <YourApp />
264
- * </DemoKitProvider>
265
- * )
266
- * }
267
- * ```
268
- */
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;
270
-
271
- /**
272
- * Hook to access demo mode state and controls
273
- *
274
- * @returns Demo mode context value with state and control methods
275
- * @throws Error if used outside of DemoKitProvider
276
- *
277
- * @example
278
- * function MyComponent() {
279
- * const { isDemoMode, isHydrated, toggle } = useDemoMode()
280
- *
281
- * // Wait for hydration before rendering demo-dependent UI
282
- * if (!isHydrated) {
283
- * return <Loading />
284
- * }
285
- *
286
- * return (
287
- * <div>
288
- * <p>Demo mode: {isDemoMode ? 'ON' : 'OFF'}</p>
289
- * <button onClick={toggle}>Toggle</button>
290
- * </div>
291
- * )
292
- * }
293
- */
294
- declare function useDemoMode(): DemoModeContextValue;
295
- /**
296
- * Hook to check if demo mode is enabled
297
- * Shorthand for useDemoMode().isDemoMode
298
- *
299
- * @returns Whether demo mode is enabled
300
- */
301
- declare function useIsDemoMode(): boolean;
302
- /**
303
- * Hook to check if the component has hydrated
304
- * Shorthand for useDemoMode().isHydrated
305
- *
306
- * @returns Whether the component has hydrated
307
- */
308
- declare function useIsHydrated(): boolean;
309
- /**
310
- * Hook to access the session state
311
- * Shorthand for useDemoMode().getSession()
312
- *
313
- * @returns The session state, or null if not yet initialized
314
- *
315
- * @example
316
- * function MyComponent() {
317
- * const session = useDemoSession()
318
- *
319
- * const cart = session?.get<CartItem[]>('cart') || []
320
- * const addToCart = (item: CartItem) => {
321
- * session?.set('cart', [...cart, item])
322
- * }
323
- *
324
- * return <CartView items={cart} onAdd={addToCart} />
325
- * }
326
- */
327
- declare function useDemoSession(): _demokit_ai_core.SessionState | null;
328
-
329
- /**
330
- * A ready-to-use banner component that shows when demo mode is active
331
- *
332
- * Displays a prominent amber banner with a label, description, and exit button.
333
- * Automatically hides when demo mode is disabled or before hydration.
334
- *
335
- * @example
336
- * function App() {
337
- * return (
338
- * <DemoKitProvider fixtures={fixtures}>
339
- * <DemoModeBanner />
340
- * <YourApp />
341
- * </DemoKitProvider>
342
- * )
343
- * }
344
- *
345
- * @example Custom labels
346
- * <DemoModeBanner
347
- * demoLabel="Preview Mode"
348
- * description="You're viewing sample data"
349
- * exitLabel="Exit Preview"
350
- * />
351
- */
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;
473
-
474
- /**
475
- * React context for demo mode state
476
- * @internal
477
- */
478
- declare const DemoModeContext: react.Context<DemoModeContextValue | undefined>;
479
-
480
- export { DemoKitProvider, type DemoKitProviderProps, DemoModeBanner, type DemoModeBannerProps, DemoModeContext, type DemoModeContextValue, DemoModeToggle, type DemoModeToggleProps, PoweredByBadge, type PoweredByBadgeProps, useDemoMode, useDemoSession, useIsDemoMode, useIsHydrated };