@demokit-ai/react 0.2.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.
@@ -0,0 +1,26 @@
1
+ import type { DemoModeBannerProps } from './types';
2
+ /**
3
+ * A ready-to-use banner component that shows when demo mode is active
4
+ *
5
+ * Displays a prominent amber banner with a label, description, and exit button.
6
+ * Automatically hides when demo mode is disabled or before hydration.
7
+ *
8
+ * @example
9
+ * function App() {
10
+ * return (
11
+ * <DemoKitProvider fixtures={fixtures}>
12
+ * <DemoModeBanner />
13
+ * <YourApp />
14
+ * </DemoKitProvider>
15
+ * )
16
+ * }
17
+ *
18
+ * @example Custom labels
19
+ * <DemoModeBanner
20
+ * demoLabel="Preview Mode"
21
+ * description="You're viewing sample data"
22
+ * exitLabel="Exit Preview"
23
+ * />
24
+ */
25
+ export declare function DemoModeBanner({ className, exitLabel, demoLabel, description, showIcon, showPoweredBy, poweredByUrl, style, onExit, }: DemoModeBannerProps): import("react/jsx-runtime").JSX.Element | null;
26
+ //# sourceMappingURL=banner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"banner.d.ts","sourceRoot":"","sources":["../src/banner.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAqElD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,SAAc,EACd,SAA4B,EAC5B,SAA8B,EAC9B,WAAmD,EACnD,QAAe,EACf,aAAoB,EACpB,YAAmC,EACnC,KAAK,EACL,MAAM,GACP,EAAE,mBAAmB,kDA0DrB"}
@@ -0,0 +1,20 @@
1
+ import type { RemoteConfig } from '@demokit-ai/core';
2
+ /**
3
+ * Create a remote source configuration for fetching fixtures from DemoKit Cloud
4
+ *
5
+ * @example
6
+ * ```tsx
7
+ * import { createRemoteSource } from '@demokit-ai/react'
8
+ *
9
+ * const source = createRemoteSource({
10
+ * apiUrl: process.env.NEXT_PUBLIC_DEMOKIT_API_URL!,
11
+ * apiKey: process.env.NEXT_PUBLIC_DEMOKIT_API_KEY!,
12
+ * })
13
+ *
14
+ * <DemoKitProvider source={source}>
15
+ * {children}
16
+ * </DemoKitProvider>
17
+ * ```
18
+ */
19
+ export declare function createRemoteSource(config: RemoteConfig): RemoteConfig;
20
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAOrE"}
@@ -0,0 +1,7 @@
1
+ import type { DemoModeContextValue } from './types';
2
+ /**
3
+ * React context for demo mode state
4
+ * @internal
5
+ */
6
+ export declare const DemoModeContext: import("react").Context<DemoModeContextValue | undefined>;
7
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAEnD;;;GAGG;AACH,eAAO,MAAM,eAAe,2DAA6D,CAAA"}
@@ -0,0 +1,59 @@
1
+ export interface UseDemoGuardOptions {
2
+ /**
3
+ * Called when a mutation is blocked in demo mode.
4
+ * Use this to show a toast or notification to the user.
5
+ * @param message - The action name or a default message
6
+ */
7
+ onBlocked?: (message: string) => void;
8
+ }
9
+ export interface DemoGuardReturn {
10
+ /**
11
+ * Whether demo mode is currently active
12
+ */
13
+ isDemoMode: boolean;
14
+ /**
15
+ * Wraps a mutation action — prevents execution in demo mode.
16
+ * When blocked, calls `onBlocked` with the action name.
17
+ *
18
+ * @param action - The mutation function to execute (only runs if NOT in demo mode)
19
+ * @param actionName - Human-readable name (e.g., "Changes saved")
20
+ * @returns `true` if the action was executed, `false` if blocked
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * const { guardMutation } = useDemoGuard({
25
+ * onBlocked: (msg) => toast.success(msg)
26
+ * })
27
+ *
28
+ * guardMutation(() => sdk.deleteItem(id), 'Item deleted')
29
+ * ```
30
+ */
31
+ guardMutation: (action: () => void | Promise<void>, actionName?: string) => boolean;
32
+ }
33
+ /**
34
+ * Hook that prevents mutations from executing in demo mode.
35
+ *
36
+ * Instead of letting mutations hit the (intercepted) API and trigger
37
+ * side effects like optimistic updates and onSuccess handlers, this
38
+ * hook blocks the mutation entirely and optionally notifies the user.
39
+ *
40
+ * @example
41
+ * ```tsx
42
+ * import { useDemoGuard } from '@demokit-ai/react'
43
+ * import { toast } from 'sonner'
44
+ *
45
+ * function MyComponent() {
46
+ * const { guardMutation } = useDemoGuard({
47
+ * onBlocked: (msg) => toast.success(msg, {
48
+ * description: 'Changes are not saved. Exit demo mode to make real changes.',
49
+ * })
50
+ * })
51
+ *
52
+ * const handleDelete = () => {
53
+ * guardMutation(() => sdk.deleteItem(id), 'Item deleted')
54
+ * }
55
+ * }
56
+ * ```
57
+ */
58
+ export declare function useDemoGuard(options?: UseDemoGuardOptions): DemoGuardReturn;
59
+ //# sourceMappingURL=guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CACtC;AAED,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,UAAU,EAAE,OAAO,CAAA;IAEnB;;;;;;;;;;;;;;;;OAgBG;IACH,aAAa,EAAE,CACb,MAAM,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAClC,UAAU,CAAC,EAAE,MAAM,KAChB,OAAO,CAAA;CACb;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,eAAe,CAyB/E"}
@@ -0,0 +1,59 @@
1
+ import type { DemoModeContextValue } from './types';
2
+ /**
3
+ * Hook to access demo mode state and controls
4
+ *
5
+ * @returns Demo mode context value with state and control methods
6
+ * @throws Error if used outside of DemoKitProvider
7
+ *
8
+ * @example
9
+ * function MyComponent() {
10
+ * const { isDemoMode, isHydrated, toggle } = useDemoMode()
11
+ *
12
+ * // Wait for hydration before rendering demo-dependent UI
13
+ * if (!isHydrated) {
14
+ * return <Loading />
15
+ * }
16
+ *
17
+ * return (
18
+ * <div>
19
+ * <p>Demo mode: {isDemoMode ? 'ON' : 'OFF'}</p>
20
+ * <button onClick={toggle}>Toggle</button>
21
+ * </div>
22
+ * )
23
+ * }
24
+ */
25
+ export declare function useDemoMode(): DemoModeContextValue;
26
+ /**
27
+ * Hook to check if demo mode is enabled
28
+ * Shorthand for useDemoMode().isDemoMode
29
+ *
30
+ * @returns Whether demo mode is enabled
31
+ */
32
+ export declare function useIsDemoMode(): boolean;
33
+ /**
34
+ * Hook to check if the component has hydrated
35
+ * Shorthand for useDemoMode().isHydrated
36
+ *
37
+ * @returns Whether the component has hydrated
38
+ */
39
+ export declare function useIsHydrated(): boolean;
40
+ /**
41
+ * Hook to access the session state
42
+ * Shorthand for useDemoMode().getSession()
43
+ *
44
+ * @returns The session state, or null if not yet initialized
45
+ *
46
+ * @example
47
+ * function MyComponent() {
48
+ * const session = useDemoSession()
49
+ *
50
+ * const cart = session?.get<CartItem[]>('cart') || []
51
+ * const addToCart = (item: CartItem) => {
52
+ * session?.set('cart', [...cart, item])
53
+ * }
54
+ *
55
+ * return <CartView items={cart} onAdd={addToCart} />
56
+ * }
57
+ */
58
+ export declare function useDemoSession(): import("@demokit-ai/core").SessionState | null;
59
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAEnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,IAAI,oBAAoB,CAWlD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,mDAE7B"}