@ereo/client 0.1.23 → 0.1.24

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,64 @@
1
+ /**
2
+ * @ereo/client - ScrollRestoration Component
3
+ *
4
+ * React component for managing scroll restoration during SPA navigation.
5
+ * Uses sessionStorage for persistence across page reloads and
6
+ * integrates with React lifecycle for proper cleanup.
7
+ */
8
+ import { createElement } from 'react';
9
+ /**
10
+ * Props for the ScrollRestoration component.
11
+ */
12
+ export interface ScrollRestorationProps {
13
+ /**
14
+ * Custom function to generate storage keys for scroll positions.
15
+ * Receives the current pathname and returns a key string.
16
+ * Defaults to using the pathname as the key.
17
+ */
18
+ getKey?: (pathname: string) => string;
19
+ /**
20
+ * CSP nonce for the inline script used during SSR hydration.
21
+ */
22
+ nonce?: string;
23
+ /**
24
+ * Storage mechanism. Defaults to 'sessionStorage'.
25
+ * 'manual' disables automatic storage (use getKey for custom logic).
26
+ */
27
+ storageKey?: string;
28
+ }
29
+ /**
30
+ * Clear all scroll positions from memory store (for testing).
31
+ */
32
+ export declare function clearScrollPositions(): void;
33
+ /**
34
+ * ScrollRestoration component.
35
+ *
36
+ * Place this once in your app (typically in the root layout) to enable
37
+ * automatic scroll position saving and restoration during SPA navigation.
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * import { ScrollRestoration } from '@ereo/client';
42
+ *
43
+ * function RootLayout({ children }) {
44
+ * return (
45
+ * <html>
46
+ * <body>
47
+ * {children}
48
+ * <ScrollRestoration />
49
+ * </body>
50
+ * </html>
51
+ * );
52
+ * }
53
+ * ```
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * // Custom key function for hash-based routing
58
+ * <ScrollRestoration
59
+ * getKey={(pathname) => pathname + window.location.hash}
60
+ * />
61
+ * ```
62
+ */
63
+ export declare function ScrollRestoration({ getKey, nonce, storageKey, }?: ScrollRestorationProps): ReturnType<typeof createElement> | null;
64
+ //# sourceMappingURL=scroll-restoration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-restoration.d.ts","sourceRoot":"","sources":["../src/scroll-restoration.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAqB,aAAa,EAAE,MAAM,OAAO,CAAC;AAGzD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAEtC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAyDD;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,KAAK,EACL,UAA0B,GAC3B,GAAE,sBAA2B,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,GAAG,IAAI,CA+EvE"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @ereo/client - useBeforeUnload Hook
3
+ *
4
+ * Registers a `beforeunload` event listener that fires when the user
5
+ * attempts to close the tab or navigate away from the page.
6
+ */
7
+ export interface UseBeforeUnloadOptions {
8
+ /** Use capture phase for the event listener */
9
+ capture?: boolean;
10
+ }
11
+ /**
12
+ * Hook that registers a `beforeunload` event listener.
13
+ * The callback ref is updated without re-registering the listener.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * useBeforeUnload((event) => {
18
+ * if (hasUnsavedChanges) {
19
+ * event.preventDefault();
20
+ * }
21
+ * });
22
+ * ```
23
+ */
24
+ export declare function useBeforeUnload(callback: (event: BeforeUnloadEvent) => void, options?: UseBeforeUnloadOptions): void;
25
+ //# sourceMappingURL=use-before-unload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-before-unload.d.ts","sourceRoot":"","sources":["../src/use-before-unload.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,WAAW,sBAAsB;IACrC,+CAA+C;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,EAC5C,OAAO,CAAC,EAAE,sBAAsB,GAC/B,IAAI,CAoBN"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @ereo/client - useNavigationType Hook
3
+ *
4
+ * Returns the type of the current navigation ('push' | 'replace' | 'pop').
5
+ */
6
+ export type NavigationType = 'push' | 'replace' | 'pop';
7
+ /**
8
+ * Hook that returns the type of the most recent navigation.
9
+ * Defaults to 'push'.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const navigationType = useNavigationType();
14
+ * // 'push' | 'replace' | 'pop'
15
+ * ```
16
+ */
17
+ export declare function useNavigationType(): NavigationType;
18
+ //# sourceMappingURL=use-navigation-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-navigation-type.d.ts","sourceRoot":"","sources":["../src/use-navigation-type.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,CAAC;AAExD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CAUlD"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * @ereo/client - View Transitions API
3
+ *
4
+ * Integration with the browser View Transitions API for smooth
5
+ * animated transitions between pages during SPA navigation.
6
+ *
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API
8
+ */
9
+ /**
10
+ * A ViewTransition object returned by document.startViewTransition().
11
+ * Mirrors the browser's ViewTransition interface.
12
+ */
13
+ export interface ViewTransition {
14
+ /** Promise that resolves when the transition animation finishes. */
15
+ finished: Promise<void>;
16
+ /** Promise that resolves when the new view is ready. */
17
+ ready: Promise<void>;
18
+ /** Promise that resolves when the old view snapshot is captured. */
19
+ updateCallbackDone: Promise<void>;
20
+ /** Skip the transition animation. */
21
+ skipTransition: () => void;
22
+ }
23
+ /**
24
+ * Options for starting a view transition.
25
+ */
26
+ export interface ViewTransitionOptions {
27
+ /**
28
+ * Custom CSS class to add to the document element during the transition.
29
+ * Useful for scoping transition animations to specific navigations.
30
+ */
31
+ className?: string;
32
+ }
33
+ /**
34
+ * State of the current view transition.
35
+ */
36
+ export interface ViewTransitionState {
37
+ /** Whether a view transition is currently in progress. */
38
+ isTransitioning: boolean;
39
+ /** The current ViewTransition object, if any. */
40
+ currentTransition: ViewTransition | null;
41
+ }
42
+ /**
43
+ * Check if the View Transitions API is supported.
44
+ */
45
+ export declare function isViewTransitionSupported(): boolean;
46
+ /**
47
+ * Start a view transition wrapping the given update callback.
48
+ * Falls back to executing the callback directly if the API is not supported.
49
+ *
50
+ * @param callback - Function that updates the DOM (e.g., navigation)
51
+ * @param options - Optional transition options
52
+ * @returns A ViewTransition object, or null if the API is not supported
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * import { startViewTransition } from '@ereo/client';
57
+ *
58
+ * startViewTransition(() => {
59
+ * // Update the DOM here
60
+ * navigate('/about');
61
+ * });
62
+ * ```
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * // With custom animation class
67
+ * const transition = startViewTransition(
68
+ * () => navigate('/dashboard'),
69
+ * { className: 'slide-left' }
70
+ * );
71
+ *
72
+ * if (transition) {
73
+ * await transition.finished;
74
+ * console.log('Transition complete');
75
+ * }
76
+ * ```
77
+ */
78
+ export declare function startViewTransition(callback: () => void | Promise<void>, options?: ViewTransitionOptions): ViewTransition | null;
79
+ /**
80
+ * Context value for view transition state.
81
+ */
82
+ export interface ViewTransitionContextValue {
83
+ isTransitioning: boolean;
84
+ currentTransition: ViewTransition | null;
85
+ }
86
+ /**
87
+ * Context for view transition state.
88
+ */
89
+ export declare const ViewTransitionContext: import("react").Context<ViewTransitionContextValue>;
90
+ /**
91
+ * Hook to get the current view transition state.
92
+ *
93
+ * @returns The current transition state
94
+ *
95
+ * @example
96
+ * ```tsx
97
+ * function MyComponent() {
98
+ * const { isTransitioning } = useViewTransitionState();
99
+ *
100
+ * return (
101
+ * <div style={{ opacity: isTransitioning ? 0.5 : 1 }}>
102
+ * Content
103
+ * </div>
104
+ * );
105
+ * }
106
+ * ```
107
+ */
108
+ export declare function useViewTransitionState(): ViewTransitionState;
109
+ /**
110
+ * Enable view transitions globally for all navigations.
111
+ * Call this in your app's initialization.
112
+ *
113
+ * @param options - Optional transition options applied to all navigations
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * import { enableViewTransitions } from '@ereo/client';
118
+ *
119
+ * // Enable for all navigations
120
+ * enableViewTransitions();
121
+ * ```
122
+ */
123
+ export declare function enableViewTransitions(options?: ViewTransitionOptions): void;
124
+ /**
125
+ * Disable view transitions globally.
126
+ */
127
+ export declare function disableViewTransitions(): void;
128
+ /**
129
+ * Check if view transitions are currently enabled.
130
+ */
131
+ export declare function areViewTransitionsEnabled(): boolean;
132
+ /**
133
+ * Reset view transitions state (for testing).
134
+ */
135
+ export declare function resetViewTransitions(): void;
136
+ //# sourceMappingURL=view-transition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view-transition.d.ts","sourceRoot":"","sources":["../src/view-transition.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,wDAAwD;IACxD,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrB,oEAAoE;IACpE,kBAAkB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,qCAAqC;IACrC,cAAc,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,eAAe,EAAE,OAAO,CAAC;IACzB,iDAAiD;IACjD,iBAAiB,EAAE,cAAc,GAAG,IAAI,CAAC;CAC1C;AAMD;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,OAAO,CAKnD;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EACpC,OAAO,CAAC,EAAE,qBAAqB,GAC9B,cAAc,GAAG,IAAI,CA4BvB;AAMD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,eAAe,EAAE,OAAO,CAAC;IACzB,iBAAiB,EAAE,cAAc,GAAG,IAAI,CAAC;CAC1C;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,qDAGhC,CAAC;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,IAAI,mBAAmB,CAM5D;AAYD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAG3E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAG7C;AAED;;GAEG;AACH,wBAAgB,yBAAyB,IAAI,OAAO,CAEnD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAG3C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ereo/client",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "license": "MIT",
5
5
  "author": "Ereo Team",
6
6
  "homepage": "https://ereo.dev",
@@ -32,7 +32,7 @@
32
32
  "typecheck": "tsc --noEmit"
33
33
  },
34
34
  "dependencies": {
35
- "@ereo/core": "^0.1.23"
35
+ "@ereo/core": "^0.1.24"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/react": "^18.2.0",