@react-motion-router/stack 2.0.0-beta.sha-679879e → 2.0.0-beta.sha-112968d

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/build/Anchor.d.ts CHANGED
@@ -30,5 +30,5 @@ interface UseIntersectionOptions {
30
30
  rootMargin?: string;
31
31
  threshold?: number | number[];
32
32
  }
33
- export declare function Anchor({ preload, goBack, params, type, href: hrefProp, navigation: navigationProp, onClick: onClickProp, preloadBehaviour, children, ...aProps }: AnchorProps): JSX.Element;
33
+ export declare function Anchor({ preload, goBack, params, type, href: hrefProp, navigation: navigationProp, onClick: onClickProp, preloadBehaviour, children, ...aProps }: AnchorProps): import("react/jsx-runtime").JSX.Element;
34
34
  export {};
@@ -1,5 +1,5 @@
1
1
  interface GestureRegionProps extends React.HTMLAttributes<HTMLDivElement> {
2
2
  disabled?: boolean;
3
3
  }
4
- export declare function GestureRegion({ disabled, children, ...props }: GestureRegionProps): JSX.Element;
4
+ export declare function GestureRegion({ disabled, children, ...props }: GestureRegionProps): import("react/jsx-runtime").JSX.Element;
5
5
  export {};
@@ -3,16 +3,16 @@ export declare class HistoryEntry implements Omit<NavigationHistoryEntry, 'url'>
3
3
  readonly routerId: string;
4
4
  readonly index: number;
5
5
  constructor(nativeEntry: NavigationHistoryEntry, routerId: string, index: number);
6
- set ondispose(handler: ((this: NavigationHistoryEntry, ev: Event) => any) | null);
7
- get ondispose(): ((this: NavigationHistoryEntry, ev: Event) => any) | null;
6
+ set ondispose(handler: ((this: NavigationHistoryEntry, ev: Event) => void) | null);
7
+ get ondispose(): ((this: NavigationHistoryEntry, ev: Event) => void) | null;
8
8
  get id(): string;
9
9
  get globalIndex(): number;
10
10
  get url(): URL | null;
11
11
  get key(): string;
12
12
  get sameDocument(): boolean;
13
- addEventListener<K extends keyof NavigationHistoryEntryEventMap>(type: K, listener: (this: NavigationHistoryEntry, ev: NavigationHistoryEntryEventMap[K]) => any, options?: boolean | AddEventListenerOptions): () => void;
13
+ addEventListener<K extends keyof NavigationHistoryEntryEventMap>(type: K, listener: (this: NavigationHistoryEntry, ev: NavigationHistoryEntryEventMap[K]) => void, options?: boolean | AddEventListenerOptions): () => void;
14
14
  addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): () => void;
15
- removeEventListener<K extends keyof NavigationHistoryEntryEventMap>(type: K, listener: (this: NavigationHistoryEntry, ev: NavigationHistoryEntryEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
15
+ removeEventListener<K extends keyof NavigationHistoryEntryEventMap>(type: K, listener: (this: NavigationHistoryEntry, ev: NavigationHistoryEntryEventMap[K]) => void, options?: boolean | EventListenerOptions): void;
16
16
  removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
17
17
  dispatchEvent(event: Event): boolean;
18
18
  getState<T>(): T;
@@ -1,10 +1,15 @@
1
- import { NavigationBase } from '../../core/build';
1
+ import { LoadNavigationTransition, NavigationBase, NavigationBaseConfig, PathPattern } from '../../core/build';
2
2
  import { GoBackOptions, GoForwardOptions, NavigateOptions, NavigationBaseOptions, NavigationProps, RouterEventMap } from './common/types';
3
3
  import { HistoryEntry } from './HistoryEntry';
4
- import { Router } from './Router';
4
+ export interface NavigationConfig extends NavigationBaseConfig<RouterEventMap> {
5
+ preload(pathname: string, props?: NavigationProps, options?: NavigationBaseOptions): Promise<boolean>;
6
+ getCommitted(): Promise<NavigationHistoryEntry> | null;
7
+ getTransition(): NavigationTransition | LoadNavigationTransition | null;
8
+ getPathPatterns(): PathPattern[];
9
+ }
5
10
  export declare class Navigation extends NavigationBase<RouterEventMap> {
6
- protected readonly router: Router;
7
- constructor(router: Router);
11
+ private readonly config;
12
+ constructor(config: NavigationConfig);
8
13
  preload(route: string, props?: NavigationProps, options?: NavigationBaseOptions): Promise<boolean>;
9
14
  replace(route: string, props?: NavigationProps, options?: NavigationBaseOptions): NavigationResult;
10
15
  push(route: string, props?: NavigationProps, options?: NavigationBaseOptions): NavigationResult;
@@ -17,9 +22,184 @@ export declare class Navigation extends NavigationBase<RouterEventMap> {
17
22
  private createForwardEvent;
18
23
  private createNavigateEvent;
19
24
  get committed(): Promise<NavigationHistoryEntry> | null;
20
- get transition(): NavigationTransition | import('../../core/build').LoadNavigationTransition | null;
25
+ get transition(): NavigationTransition | LoadNavigationTransition | null;
21
26
  get globalEntries(): NavigationHistoryEntry[];
27
+ /**
28
+ * Returns the list of history entries **owned by this router**, derived from the
29
+ * browser’s global navigation history.
30
+ *
31
+ * ---
32
+ *
33
+ * ### Mental model
34
+ *
35
+ * The Web Navigation API exposes a **single, flat history list**.
36
+ * This router projects a **scoped, ordered view** of that list ensuring the
37
+ * router can only see entries it created.
38
+ *
39
+ * Each global entry is classified as one of:
40
+ *
41
+ * - **Owned by this router**
42
+ * - **Owned by a nested router**
43
+ * - **Owned by a different (foreign) router**
44
+ *
45
+ * The resulting entry list is built by iterating global history **from the
46
+ * beginning**, applying ownership rules, and stopping when ownership is lost.
47
+ *
48
+ * ---
49
+ *
50
+ * ### Ownership & contiguity rules
51
+ *
52
+ * 1. **Entries owned by this router**
53
+ * - Are included
54
+ * - Preserve global ordering
55
+ *
56
+ * 2. **Entries owned by nested routers**
57
+ * - Exactly **one entry is included** (the nested router’s mount point),
58
+ * because it must be rendered by the parent router
59
+ * - All subsequent entries belonging to that same nested scope are excluded
60
+ *
61
+ * 3. **Entries owned by a foreign router**
62
+ * - Are excluded
63
+ * - **Terminate entry collection** once at least one entry has been matched
64
+ *
65
+ * This means contiguity is enforced **only across routers that cannot be
66
+ * matched by this router at all**.
67
+ *
68
+ * ---
69
+ *
70
+ * ### Important invariants
71
+ *
72
+ * - Returned entries are always in **global history order**
73
+ * - Local indices are **stable and monotonic**
74
+ * - Nested router entries never leak into the parent router
75
+ * - Entry collection stops once navigation leaves this router’s ownership
76
+ * after it has begun
77
+ *
78
+ * ---
79
+ *
80
+ * ### Example
81
+ *
82
+ * Global history:
83
+ * ```
84
+ * 0: / (parent)
85
+ * 1: /world (parent)
86
+ * 2: /world/1 (nested mount point)
87
+ * 3: /world/2 (nested)
88
+ * 4: /about (parent)
89
+ * 5: /other-router/page (foreign)
90
+ * 6: / (parent)
91
+ * ```
92
+ *
93
+ * Parent router entries:
94
+ * ```
95
+ * /, /world, /world/1, /about
96
+ * ```
97
+ *
98
+ * Collection stops at index 5 because ownership is transferred to a
99
+ * foreign router.
100
+ *
101
+ *
102
+ * This approach balances correctness, simplicity, and predictable behavior
103
+ * without requiring global history rewriting or fragile index arithmetic.
104
+ */
22
105
  get entries(): HistoryEntry[];
106
+ /**
107
+ * Returns the **local history index** for this router, derived from the
108
+ * browser’s global navigation state.
109
+ *
110
+ * ---
111
+ *
112
+ * ### Problem this solves
113
+ *
114
+ * The Web Navigation API exposes a **single, flat history list**.
115
+ * This router exposes a **scoped history view** that:
116
+ *
117
+ * - filters out entries owned by nested routers
118
+ * - preserves global ordering
119
+ * - reindexes entries locally
120
+ *
121
+ * As a result, there is **no arithmetic relationship** between:
122
+ *
123
+ * - `window.navigation.currentEntry.index` (global)
124
+ * - this router’s local `index`
125
+ *
126
+ * This getter computes the local index **by identity**, not position.
127
+ *
128
+ * ---
129
+ *
130
+ * ### High-level behavior
131
+ *
132
+ * The returned index is:
133
+ *
134
+ * > the index of the **most recent local entry** that appears in the
135
+ * > browser’s global history **at or before** the current global entry.
136
+ *
137
+ * ---
138
+ *
139
+ * ### Resolution strategy
140
+ *
141
+ * 1. If the current global index is **before** this router’s first entry,
142
+ * the index resolves to `0`.
143
+ *
144
+ * 2. If the current global index is **after** this router’s last entry,
145
+ * the index resolves to `entries.length - 1`.
146
+ *
147
+ * 3. Otherwise:
148
+ * - A window of global history is sliced from the first local entry
149
+ * up to and including the current global entry.
150
+ * - Local entries are scanned **from newest to oldest**.
151
+ * - The first local entry whose `key` appears in that global slice
152
+ * determines the local index.
153
+ *
154
+ * Entry identity is determined by **history entry keys**, not URLs or
155
+ * global indices.
156
+ *
157
+ * ---
158
+ *
159
+ * ### Why key-based matching is required
160
+ *
161
+ * - Global indices are sparse once nested routers are involved
162
+ * - URLs may repeat or be replaced
163
+ * - History entries can be inserted between parent entries
164
+ *
165
+ * Keys provide the only stable identity that survives these cases.
166
+ *
167
+ * ---
168
+ *
169
+ * ### Invariant
170
+ *
171
+ * The returned index always satisfies:
172
+ *
173
+ * ```
174
+ * 0 ≤ index < entries.length
175
+ * ```
176
+ *
177
+ * and monotonically tracks navigation through global history.
178
+ *
179
+ * ---
180
+ *
181
+ * ### Example
182
+ *
183
+ * Global history:
184
+ * ```
185
+ * 0: /
186
+ * 1: /world
187
+ * 2: /world/1 (nested)
188
+ * 3: /about ← current
189
+ * ```
190
+ *
191
+ * Local router entries:
192
+ * ```
193
+ * / (index 0)
194
+ * /world (index 1)
195
+ * /about (index 2)
196
+ * ```
197
+ *
198
+ * Result:
199
+ * ```
200
+ * index === 2
201
+ * ```
202
+ */
23
203
  get index(): number;
24
204
  get previous(): HistoryEntry | null;
25
205
  get next(): HistoryEntry | null;
@@ -0,0 +1,4 @@
1
+ export declare const FIRST_INDEX = 0;
2
+ export declare const SECOND_INDEX = 1;
3
+ export declare const THIRD_INDEX = 2;
4
+ export declare const FOURTH_INDEX = 3;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -6,3 +6,4 @@ export declare const DEFAULT_GESTURE_CONFIG: {
6
6
  readonly gestureDisabled: false;
7
7
  };
8
8
  export declare const DEFAULT_PRELOAD_FORCE_THRESHOLD = 0.5;
9
+ export declare const DEFAULT_PLAYBACK_RATE = 1;
@@ -4,11 +4,11 @@ export declare class NavigateEvent extends Event {
4
4
  readonly routerId: string;
5
5
  readonly route: string;
6
6
  readonly props: NavigationProps;
7
- readonly navigationType: NonNullable<NavigateOptions["type"]>;
7
+ readonly navigationType: NonNullable<NavigateOptions['type']>;
8
8
  readonly signal: AbortSignal;
9
9
  readonly committed: Promise<NavigationHistoryEntry>;
10
10
  readonly transition: NavigationTransition;
11
- constructor(routerId: string, route: string, props: NavigationProps, type: NavigateOptions["type"], signal: AbortSignal, committed: Promise<NavigationHistoryEntry>, transition: NavigationTransition);
11
+ constructor(routerId: string, route: string, props: NavigationProps, type: NavigateOptions['type'], signal: AbortSignal, committed: Promise<NavigationHistoryEntry>, transition: NavigationTransition);
12
12
  }
13
13
  export declare class BackEvent extends Event {
14
14
  readonly routerId: string;
@@ -2,7 +2,11 @@ import { PlainObject } from '../../../core/build';
2
2
  import { Navigation } from '../Navigation';
3
3
  import { Router } from '../Router';
4
4
  import { RouteProp } from './types';
5
+ import { RefObject } from 'react';
5
6
  export declare function useNavigation(): Navigation;
6
7
  export declare function useRouter(): Router;
7
8
  export declare function useRoute<T extends PlainObject = PlainObject>(): RouteProp<T>;
8
9
  export declare function useParams<K extends string, S>(key: K, initialParams: S | (() => S)): [S, import('react').Dispatch<import('react').SetStateAction<S>>];
10
+ type EventListenerOptions = boolean | AddEventListenerOptions;
11
+ export declare function useEventListener<K extends keyof HTMLElementEventMap>(ref: RefObject<HTMLElement | null>, eventName: K, handler: (event: HTMLElementEventMap[K]) => void, options?: EventListenerOptions): void;
12
+ export {};
@@ -1,9 +1,8 @@
1
1
  export declare class PromiseWrapper<T> {
2
+ #private;
2
3
  promise: Promise<T>;
3
4
  state: 'pending' | 'resolved' | 'rejected';
4
- nativeResolve: ((value: T | PromiseLike<T>) => void) | null;
5
- nativeReject: ((reason: any) => void) | null;
6
5
  constructor();
7
6
  resolve(value: T): void;
8
- reject(reason: any): void;
7
+ reject(reason: unknown): void;
9
8
  }