@use-stall/types 0.3.4 → 0.3.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@use-stall/types",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "Type declarations for Stall SDKs",
5
5
  "types": "index.d.ts",
6
6
  "type": "module",
@@ -3,12 +3,11 @@
3
3
  export interface UnifiedCustomerType {
4
4
  id: string;
5
5
  email: string;
6
- default_billing_address_id: string;
7
- default_shipping_address_id: string;
8
6
  company_name: string;
9
7
  first_name: string;
10
8
  last_name: string;
11
- addresses: UnifiedCustomerAddressType[];
9
+ billing_address: UnifiedCustomerAddressType;
10
+ shipping_address: UnifiedCustomerAddressType;
12
11
  phone: string;
13
12
  metadata: {
14
13
  stall_offline_id: string;
@@ -23,10 +22,7 @@ export interface UnifiedCustomerType {
23
22
  }
24
23
 
25
24
  export interface UnifiedCustomerAddressType {
26
- id: string;
27
25
  address_name: string;
28
- is_default_shipping: boolean;
29
- is_default_billing: boolean;
30
26
  company: string;
31
27
  first_name: string;
32
28
  last_name: string;
@@ -1,8 +1,10 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { UnifiedOrderType } from "./orders";
3
- import { ComponentType } from "./utils/react";
4
- import type { Router } from "./utils/router";
5
- import { LookupGroupRouteType } from "./utils/lookup";
3
+ import {
4
+ LookupActionHelpersType,
5
+ LookupGroupRouteType,
6
+ LookupListFilterType,
7
+ } from "./lookup";
6
8
  import type { CoreConfig } from "./core-sdk";
7
9
 
8
10
  interface StallExtension {
@@ -28,22 +30,23 @@ interface ExtensionActionShortcut {
28
30
  }
29
31
 
30
32
  interface ExtensionLookupAction {
31
- native: boolean;
32
- name: string;
33
+ id: string;
33
34
  label: string;
34
- static_args: Record<string, any>;
35
- close_on_complete: boolean; // Close lookup
35
+ close_on_complete?: boolean; // Close lookup
36
36
  reopen_on_return?: boolean; // Reopen lookup on return from an external page
37
37
  always_show?: boolean; // Always show the action in the lookup even if no item is selected or highlighted
38
38
  shortcut?: ExtensionActionShortcut;
39
39
  paths?: string[]; // You can specify a list of paths where this action should be available, when left empty it will be available everywhere
40
+ static_args?: Record<string, any>;
41
+ run: (arg: ExtensionLookupActionArgs) => Promise<void> | void;
40
42
  }
41
43
 
42
- interface ExtensionActionFunctionProps {
43
- static_args: Record<string, any>;
44
- item: any;
45
- router: Router;
44
+ interface ExtensionLookupActionArgs {
45
+ item: any | null;
46
46
  active_group: LookupGroupRouteType;
47
+ search_query: string;
48
+ helpers: LookupActionHelpersType;
49
+ static_args: Record<string, any>;
47
50
  action: ExtensionLookupAction;
48
51
  }
49
52
 
@@ -88,12 +91,20 @@ type ListFilters = {
88
91
  dynamic: boolean;
89
92
  };
90
93
 
94
+ interface ExtensionLookupFetchArgs {
95
+ filters: LookupListFilterType[];
96
+ active_group: LookupGroupRouteType;
97
+ parent_item: Record<string, any>;
98
+ search_query: string;
99
+ helpers: LookupActionHelpersType;
100
+ }
101
+
91
102
  interface LocalListUIComponent {
92
103
  id: string;
93
104
  title: string;
94
105
  description: string;
95
106
  data_origin: "local";
96
- filters: ListFilters[];
107
+ filters: LookupListFilterType[];
97
108
  sorting: {
98
109
  key: string;
99
110
  order: "asc" | "desc";
@@ -108,26 +119,22 @@ interface RemoteListUIComponent {
108
119
  title: string;
109
120
  description: string;
110
121
  data_origin: "remote";
111
- filters: ListFilters[];
122
+ filters: LookupListFilterType[];
112
123
  sorting: {
113
124
  key: string;
114
125
  order: "asc" | "desc";
115
126
  };
116
127
  source: string;
128
+ fetch: (arg: ExtensionLookupFetchArgs) => Promise<any[]> | any[];
117
129
  keys: ListKeys;
118
130
  actions: ExtensionLookupAction[];
119
131
  }
120
132
 
121
133
  type ExtensionLookupGroup = LocalListUIComponent | RemoteListUIComponent;
122
134
 
123
- interface UIProps {
135
+ interface RuntimeProps {
124
136
  item: any;
125
- search_query: Record<string, string>;
126
137
  base_currency: string;
127
- active_cart: UnifiedOrderType | null;
128
- BackButton: ComponentType<any>;
129
- LoaderComponent: ComponentType<any>;
130
- router: Router;
131
138
  stall: CoreConfig;
132
139
  }
133
140
 
@@ -160,14 +167,15 @@ export type {
160
167
  ExtensionPage,
161
168
  ExtensionActionShortcut,
162
169
  ExtensionLookupAction,
163
- ExtensionActionFunctionProps,
170
+ ExtensionLookupActionArgs,
171
+ ExtensionLookupFetchArgs,
164
172
  ListFilters,
165
173
  ListFormatKey,
166
174
  ListKeys,
167
175
  LocalListUIComponent,
168
176
  RemoteListUIComponent,
169
177
  ExtensionLookupGroup,
170
- UIProps,
178
+ RuntimeProps,
171
179
  StallExtensionConfig,
172
180
  };
173
181
 
package/src/lookup.d.ts CHANGED
@@ -1,45 +1,58 @@
1
- import { ExtensionModule } from "@/extensions/types";
2
- import React from "react";
3
-
4
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
5
- export interface LookUpStateType {
6
- active_group: LookupGroupRouteType | undefined;
7
- routes: LookupGroupRouteType[];
8
- search_query: string;
9
- is_shortcut?: boolean;
2
+ export type LookupValueType = "string" | "number" | "array";
3
+
4
+ export interface LookupListFilterType {
5
+ key: string;
6
+ type: LookupValueType;
7
+ query_value: string;
8
+ dynamic: boolean;
9
+ }
10
+
11
+ export interface LookupRouteExtensionType {
12
+ id: string;
13
+ title: string;
10
14
  }
11
15
 
12
16
  export interface LookupGroupRouteType {
13
17
  id: string;
14
18
  title: string;
15
- extension: {
16
- id: string;
17
- title: string;
18
- };
19
+ extension: LookupRouteExtensionType;
19
20
  previous_route_item: Record<string, any>;
20
- filters?: LookupListFilters[];
21
+ filters?: LookupListFilterType[];
21
22
  }
22
23
 
23
- export type LookupListFilters = {
24
- key: string;
25
- type: "string" | "number" | "array";
26
- query_value: string;
27
- dynamic: boolean;
28
- };
24
+ export interface LookupStateType {
25
+ active_group: LookupGroupRouteType | undefined;
26
+ routes: LookupGroupRouteType[];
27
+ search_query: string;
28
+ is_shortcut?: boolean;
29
+ }
29
30
 
30
- export type ActionTriggerType = null | {
31
- global: boolean;
32
- };
31
+ export interface LookupLastInstanceType extends LookupStateType {
32
+ path: string;
33
+ }
34
+
35
+ export interface LookupOpenGroupArgsType {
36
+ group: Omit<LookupGroupRouteType, "previous_route_item">;
37
+ item?: Record<string, any>;
38
+ }
33
39
 
34
- export interface LookUpContextType {
35
- actionsTriggered: ActionTriggerType;
36
- triggerActions: (state: ActionTriggerType) => void;
37
- lookUpSearchInputRef: React.RefObject<HTMLInputElement>;
38
- closeLookUp: (force?: boolean) => void;
39
- module: ExtensionModule | null;
40
- loading: boolean;
41
- error: Error | null;
42
- look_up: LookUpStateType;
40
+ export interface LookupActionHelpersType {
41
+ navigate: (path: string | number, options?: { replace?: boolean }) => void;
42
+ open_group: (arg: LookupOpenGroupArgsType) => void;
43
+ go_back: (force?: boolean) => void;
44
+ close_lookup: (force?: boolean) => void;
45
+ set_search_query: (value: string) => void;
46
+ get_lookup_state: () => LookupStateType | null;
47
+ }
48
+
49
+ export interface LookUpStateType {
43
50
  active_group: LookupGroupRouteType | undefined;
44
- handleInputsKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void;
51
+ routes: LookupGroupRouteType[];
52
+ search_query: string;
53
+ is_shortcut?: boolean;
45
54
  }
55
+
56
+ export type LookupActionTriggerType = null | {
57
+ global: boolean;
58
+ };
@@ -1,17 +0,0 @@
1
- export interface LookupGroupRouteType {
2
- id: string;
3
- title: string;
4
- extension: {
5
- id: string;
6
- title: string;
7
- };
8
- previous_route_item: Record<string, any>;
9
- filters?: LookupListFilters[];
10
- }
11
-
12
- export type LookupListFilters = {
13
- key: string;
14
- type: "string" | "number" | "array";
15
- query_value: string;
16
- dynamic: boolean;
17
- };
@@ -1,34 +0,0 @@
1
- export type ReactText = string | number;
2
- export type ReactChild = ReactElement | ReactText;
3
- export type ReactFragment = Iterable<ReactNode>;
4
-
5
- export interface ReactPortal {
6
- key: string | null;
7
- children: ReactNode;
8
- type: string | ComponentType<any>;
9
- props: any;
10
- }
11
-
12
- export type ReactNode =
13
- | ReactChild
14
- | ReactFragment
15
- | ReactPortal
16
- | boolean
17
- | null
18
- | undefined;
19
-
20
- export interface ReactElement<P = any> {
21
- type: string | ComponentType<P>;
22
- props: P & { children?: ReactNode }; // ← children must be here
23
- key: string | null;
24
- }
25
-
26
- export interface FunctionComponent<P = {}> {
27
- (props: P): ReactElement<any> | null;
28
- }
29
-
30
- export interface ComponentClass<P = {}> {
31
- new (props: P): { render(): ReactNode };
32
- }
33
-
34
- export type ComponentType<P = {}> = FunctionComponent<P> | ComponentClass<P>;
@@ -1,637 +0,0 @@
1
- // ─── Primitive / shared types ────────────────────────────────────────────────
2
-
3
- export type Primitive = string | number | boolean | null | undefined;
4
-
5
- /** A URL-safe path made up of its three constituent parts. */
6
- export interface Path {
7
- /** The portion of the URL pathname before any query string. */
8
- pathname: string;
9
- /** The URL search string, starting with `?`. */
10
- search: string;
11
- /** The URL fragment identifier, starting with `#`. */
12
- hash: string;
13
- }
14
-
15
- /** Accepted values for the `to` argument of `navigate`. */
16
- export type To = string | Partial<Path>;
17
-
18
- /** A fully-resolved browser Location, augmented with router-level state. */
19
- export interface Location extends Path {
20
- /**
21
- * A value of arbitrary data associated with this location.
22
- */
23
- state: any;
24
- /**
25
- * A unique string associated with this location. May be used to safely store
26
- * and retrieve data in some other storage API, like `localStorage`.
27
- */
28
- key: string;
29
- }
30
-
31
- // ─── History ─────────────────────────────────────────────────────────────────
32
-
33
- export type Action = "POP" | "PUSH" | "REPLACE";
34
-
35
- export interface Update {
36
- action: Action;
37
- location: Location;
38
- delta: number | null;
39
- }
40
-
41
- export interface Listener {
42
- (update: Update): void;
43
- }
44
-
45
- // ─── Route objects ────────────────────────────────────────────────────────────
46
-
47
- export type AgnosticRouteMatch<
48
- ParamsKey extends string = string,
49
- RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject
50
- > = {
51
- params: Params<ParamsKey>;
52
- pathname: string;
53
- pathnameBase: string;
54
- route: RouteObjectType;
55
- };
56
-
57
- export interface IndexRouteObject {
58
- caseSensitive?: boolean;
59
- path?: string;
60
- id?: string;
61
- loader?: LoaderFunction;
62
- action?: ActionFunction;
63
- hasErrorBoundary?: boolean;
64
- shouldRevalidate?: ShouldRevalidateFunction;
65
- handle?: RouteObject["handle"];
66
- index: true;
67
- children?: undefined;
68
- element?: React.ReactNode | null;
69
- hydrateFallbackElement?: React.ReactNode | null;
70
- errorElement?: React.ReactNode | null;
71
- Component?: React.ComponentType | null;
72
- HydrateFallback?: React.ComponentType | null;
73
- ErrorBoundary?: React.ComponentType | null;
74
- lazy?: LazyRouteFunction<RouteObject>;
75
- }
76
-
77
- export interface NonIndexRouteObject {
78
- caseSensitive?: boolean;
79
- path?: string;
80
- id?: string;
81
- loader?: LoaderFunction;
82
- action?: ActionFunction;
83
- hasErrorBoundary?: boolean;
84
- shouldRevalidate?: ShouldRevalidateFunction;
85
- handle?: any;
86
- index?: false;
87
- children?: RouteObject[];
88
- element?: React.ReactNode | null;
89
- hydrateFallbackElement?: React.ReactNode | null;
90
- errorElement?: React.ReactNode | null;
91
- Component?: React.ComponentType | null;
92
- HydrateFallback?: React.ComponentType | null;
93
- ErrorBoundary?: React.ComponentType | null;
94
- lazy?: LazyRouteFunction<RouteObject>;
95
- }
96
-
97
- export type RouteObject = IndexRouteObject | NonIndexRouteObject;
98
-
99
- /**
100
- * Framework-agnostic route object — the underlying shape the router core
101
- * operates on (no React-specific fields).
102
- */
103
- export interface AgnosticRouteObject {
104
- caseSensitive?: boolean;
105
- children?: AgnosticRouteObject[];
106
- element?: any;
107
- index?: boolean;
108
- path?: string;
109
- id?: string;
110
- loader?: LoaderFunction;
111
- action?: ActionFunction;
112
- hasErrorBoundary?: boolean;
113
- shouldRevalidate?: ShouldRevalidateFunction;
114
- handle?: any;
115
- lazy?: LazyRouteFunction<AgnosticRouteObject>;
116
- }
117
-
118
- export interface AgnosticDataRouteObject extends AgnosticRouteObject {
119
- children?: AgnosticDataRouteObject[];
120
- id: string;
121
- }
122
-
123
- // ─── Params ──────────────────────────────────────────────────────────────────
124
-
125
- export type Params<Key extends string = string> = {
126
- readonly [key in Key]: string | undefined;
127
- };
128
-
129
- // ─── Loader / action functions ────────────────────────────────────────────────
130
-
131
- export type LoaderFunctionArgs<Context = any> = {
132
- request: Request;
133
- params: Params;
134
- context?: Context;
135
- };
136
-
137
- export type ActionFunctionArgs<Context = any> = {
138
- request: Request;
139
- params: Params;
140
- context?: Context;
141
- };
142
-
143
- export interface LoaderFunction<Context = any> {
144
- (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown):
145
- | Promise<Response>
146
- | Response
147
- | Promise<any>
148
- | any;
149
- }
150
-
151
- export interface ActionFunction<Context = any> {
152
- (args: ActionFunctionArgs<Context>, handlerCtx?: unknown):
153
- | Promise<Response>
154
- | Response
155
- | Promise<any>
156
- | any;
157
- }
158
-
159
- export interface ShouldRevalidateFunctionArgs {
160
- currentUrl: URL;
161
- currentParams: Params;
162
- nextUrl: URL;
163
- nextParams: Params;
164
- formMethod?: string;
165
- formAction?: string;
166
- formEncType?: string;
167
- text?: string;
168
- formData?: FormData;
169
- json?: any;
170
- actionStatus?: number;
171
- actionResult?: any;
172
- defaultShouldRevalidate: boolean;
173
- }
174
-
175
- export interface ShouldRevalidateFunction {
176
- (args: ShouldRevalidateFunctionArgs): boolean;
177
- }
178
-
179
- export type LazyRouteFunction<R extends AgnosticRouteObject> = () => Promise<
180
- Omit<R, "lazy" | "id" | "index" | "children">
181
- >;
182
-
183
- // ─── Navigation ──────────────────────────────────────────────────────────────
184
-
185
- export type FormMethod =
186
- | "get"
187
- | "post"
188
- | "put"
189
- | "patch"
190
- | "delete"
191
- | "GET"
192
- | "POST"
193
- | "PUT"
194
- | "PATCH"
195
- | "DELETE";
196
-
197
- export type FormEncType =
198
- | "application/x-www-form-urlencoded"
199
- | "multipart/form-data"
200
- | "application/json"
201
- | "text/plain";
202
-
203
- export type RelativeRoutingType = "route" | "path";
204
-
205
- interface NavigateOptions {
206
- replace?: boolean;
207
- state?: any;
208
- relative?: RelativeRoutingType;
209
- flushSync?: boolean;
210
- viewTransition?: boolean;
211
- }
212
-
213
- export interface RouterNavigateOptions extends NavigateOptions {
214
- fromRouteId?: string;
215
- /** Submission options */
216
- formMethod?: FormMethod;
217
- formAction?: string;
218
- formEncType?: FormEncType;
219
- body?: any;
220
- formData?: FormData;
221
- json?: any;
222
- text?: string;
223
- /** Replace / unstable flags */
224
- preventScrollReset?: boolean;
225
- }
226
-
227
- export interface RouterFetchOptions {
228
- formMethod?: FormMethod;
229
- formAction?: string;
230
- formEncType?: FormEncType;
231
- body?: any;
232
- formData?: FormData;
233
- json?: any;
234
- text?: string;
235
- preventScrollReset?: boolean;
236
- }
237
-
238
- // ─── Navigation state ─────────────────────────────────────────────────────────
239
-
240
- export type NavigationState =
241
- | { state: "idle"; location?: undefined; formMethod?: undefined; formAction?: undefined; formEncType?: undefined; formData?: undefined; json?: undefined; text?: undefined }
242
- | { state: "loading"; location: Location; formMethod?: FormMethod; formAction?: string; formEncType?: FormEncType; formData?: FormData; json?: any; text?: string }
243
- | { state: "submitting"; location: Location; formMethod: FormMethod; formAction: string; formEncType: FormEncType; formData?: FormData; json?: any; text?: string };
244
-
245
- export type Navigation = NavigationState;
246
-
247
- // ─── Fetcher ─────────────────────────────────────────────────────────────────
248
-
249
- export type FetcherState =
250
- | { state: "idle"; data: undefined; formMethod?: undefined; formAction?: undefined; formEncType?: undefined; formData?: undefined; json?: undefined; text?: undefined }
251
- | { state: "loading"; data: undefined; formMethod?: FormMethod; formAction?: string; formEncType?: FormEncType; formData?: FormData; json?: any; text?: string }
252
- | { state: "submitting"; data: undefined; formMethod: FormMethod; formAction: string; formEncType: FormEncType; formData?: FormData; json?: any; text?: string };
253
-
254
- export type Fetcher<TData = any> = (
255
- | { state: "idle"; data: TData | undefined; formMethod?: undefined; formAction?: undefined; formEncType?: undefined; formData?: undefined; json?: undefined; text?: undefined }
256
- | { state: "loading"; data: TData | undefined; formMethod?: FormMethod; formAction?: string; formEncType?: FormEncType; formData?: FormData; json?: any; text?: string }
257
- | { state: "submitting"; data: TData | undefined; formMethod: FormMethod; formAction: string; formEncType: FormEncType; formData?: FormData; json?: any; text?: string }
258
- );
259
-
260
- // ─── Blocker ─────────────────────────────────────────────────────────────────
261
-
262
- export type BlockerFunction = (args: {
263
- currentLocation: Location;
264
- nextLocation: Location;
265
- historyAction: Action;
266
- }) => boolean;
267
-
268
- export type Blocker =
269
- | { state: "unblocked"; reset: undefined; proceed: undefined; location: undefined }
270
- | { state: "blocked"; reset: () => void; proceed: () => void; location: Location }
271
- | { state: "proceeding"; reset: undefined; proceed: undefined; location: Location };
272
-
273
- // ─── Revalidation ────────────────────────────────────────────────────────────
274
-
275
- export type RevalidationState = "idle" | "loading";
276
-
277
- // ─── Deferred data ───────────────────────────────────────────────────────────
278
-
279
- export interface DeferredData {
280
- readonly done: boolean;
281
- readonly unwrappedData: Record<string, any>;
282
- subscribe(fn: (aborted: boolean, settledKey?: string) => void): boolean;
283
- cancel(): void;
284
- resolveData(signal: AbortSignal): Promise<boolean>;
285
- }
286
-
287
- // ─── Router state ─────────────────────────────────────────────────────────────
288
-
289
- export interface RouterState {
290
- historyAction: Action;
291
- location: Location;
292
- matches: AgnosticDataRouteMatch[];
293
- initialized: boolean;
294
- navigation: Navigation;
295
- restoreScrollPosition: number | false | null;
296
- preventScrollReset: boolean;
297
- revalidation: RevalidationState;
298
- loaderData: RouteData;
299
- actionData: RouteData | null;
300
- errors: RouteData | null;
301
- fetchers: Map<string, Fetcher>;
302
- blockers: Map<string, Blocker>;
303
- }
304
-
305
- export type AgnosticDataRouteMatch = AgnosticRouteMatch<
306
- string,
307
- AgnosticDataRouteObject
308
- >;
309
-
310
- export type RouteData = {
311
- [routeId: string]: any;
312
- };
313
-
314
- // ─── Scroll restoration ───────────────────────────────────────────────────────
315
-
316
- export type GetScrollPositionFunction = () => number;
317
-
318
- export type GetScrollRestorationKeyFunction = (
319
- location: Location,
320
- matches: AgnosticDataRouteMatch[]
321
- ) => string;
322
-
323
- // ─── Future config ────────────────────────────────────────────────────────────
324
-
325
- export interface FutureConfig {
326
- unstable_skipActionErrorRevalidation: boolean;
327
- }
328
-
329
- // ─── Router init ─────────────────────────────────────────────────────────────
330
-
331
- export interface RouterInit {
332
- routes: AgnosticRouteObject[];
333
- history: {
334
- readonly action: Action;
335
- readonly location: Location;
336
- listen(listener: Listener): () => void;
337
- createHref(to: To): string;
338
- encodeLocation(to: To): Path;
339
- push(to: To, state?: any): void;
340
- replace(to: To, state?: any): void;
341
- go(delta: number): void;
342
- back(): void;
343
- forward(): void;
344
- };
345
- basename?: string;
346
- mapRouteProperties?: (route: AgnosticRouteObject) => Partial<AgnosticRouteObject>;
347
- future?: Partial<FutureConfig>;
348
- hydrationData?: {
349
- loaderData?: RouteData;
350
- actionData?: RouteData | null;
351
- errors?: RouteData | null;
352
- };
353
- window?: Window;
354
- dataStrategy?: DataStrategyFunction;
355
- patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
356
- }
357
-
358
- // ─── Data strategy ───────────────────────────────────────────────────────────
359
-
360
- export type DataStrategyMatch = AgnosticRouteMatch<string, AgnosticDataRouteObject> & {
361
- shouldLoad: boolean;
362
- resolve: (
363
- handlerOverride?: (
364
- handler: (ctx?: unknown) => DataFunctionReturnValue
365
- ) => DataFunctionReturnValue
366
- ) => Promise<DataStrategyResult>;
367
- };
368
-
369
- export type DataFunctionReturnValue =
370
- | Promise<Response>
371
- | Response
372
- | Promise<any>
373
- | any;
374
-
375
- export type DataStrategyResult =
376
- | { type: "data"; result: any }
377
- | { type: "error"; result: any };
378
-
379
- export interface DataStrategyFunctionArgs<Context = any> {
380
- request: Request;
381
- params: Params;
382
- context?: Context;
383
- matches: DataStrategyMatch[];
384
- fetcherKey: string | null;
385
- }
386
-
387
- export interface DataStrategyFunction {
388
- (args: DataStrategyFunctionArgs): Promise<Record<string, DataStrategyResult>>;
389
- }
390
-
391
- // ─── Patch routes on navigation ───────────────────────────────────────────────
392
-
393
- export interface PatchRoutesOnNavigationFunctionArgs {
394
- path: string;
395
- matches: AgnosticRouteMatch[];
396
- patch: (routeId: string | null, children: AgnosticRouteObject[]) => void;
397
- signal: AbortSignal;
398
- }
399
-
400
- export interface PatchRoutesOnNavigationFunction {
401
- (opts: PatchRoutesOnNavigationFunctionArgs): void | Promise<void>;
402
- }
403
-
404
- // ─── Subscriber ──────────────────────────────────────────────────────────────
405
-
406
- export type RouterSubscriber = (
407
- state: RouterState,
408
- opts: { deletedFetchers: string[]; flushSync: boolean; viewTransitionOpts?: ViewTransitionOpts }
409
- ) => void;
410
-
411
- export interface ViewTransitionOpts {
412
- currentLocation: Location;
413
- nextLocation: Location;
414
- }
415
-
416
- // ─── Router interface (original, now fully self-contained) ────────────────────
417
-
418
- export interface Router {
419
- /**
420
- * @internal
421
- * PRIVATE - DO NOT USE
422
- *
423
- * Return the basename for the router
424
- */
425
- get basename(): RouterInit["basename"];
426
-
427
- /**
428
- * @internal
429
- * PRIVATE - DO NOT USE
430
- *
431
- * Return the future config for the router
432
- */
433
- get future(): FutureConfig;
434
-
435
- /**
436
- * @internal
437
- * PRIVATE - DO NOT USE
438
- *
439
- * Return the current state of the router
440
- */
441
- get state(): RouterState;
442
-
443
- /**
444
- * @internal
445
- * PRIVATE - DO NOT USE
446
- *
447
- * Return the routes for this router instance
448
- */
449
- get routes(): AgnosticDataRouteObject[];
450
-
451
- /**
452
- * @internal
453
- * PRIVATE - DO NOT USE
454
- *
455
- * Return the window associated with the router
456
- */
457
- get window(): RouterInit["window"];
458
-
459
- /**
460
- * @internal
461
- * PRIVATE - DO NOT USE
462
- *
463
- * Initialize the router, including adding history listeners and kicking off
464
- * initial data fetches. Returns a function to cleanup listeners and abort
465
- * any in-progress loads.
466
- */
467
- initialize(): Router;
468
-
469
- /**
470
- * @internal
471
- * PRIVATE - DO NOT USE
472
- *
473
- * Subscribe to router.state updates
474
- *
475
- * @param fn function to call with the new state
476
- */
477
- subscribe(fn: RouterSubscriber): () => void;
478
-
479
- /**
480
- * @internal
481
- * PRIVATE - DO NOT USE
482
- *
483
- * Enable scroll restoration behavior in the router
484
- *
485
- * @param savedScrollPositions Object that will manage positions, in case
486
- * it's being restored from sessionStorage
487
- * @param getScrollPosition Function to get the active Y scroll position
488
- * @param getKey Function to get the key to use for restoration
489
- */
490
- enableScrollRestoration(
491
- savedScrollPositions: Record<string, number>,
492
- getScrollPosition: GetScrollPositionFunction,
493
- getKey?: GetScrollRestorationKeyFunction
494
- ): () => void;
495
-
496
- /**
497
- * @internal
498
- * PRIVATE - DO NOT USE
499
- *
500
- * Navigate forward/backward in the history stack
501
- * @param to Delta to move in the history stack
502
- */
503
- navigate(to: number): Promise<void>;
504
-
505
- /**
506
- * Navigate to the given path
507
- * @param to Path to navigate to
508
- * @param opts Navigation options (method, submission, etc.)
509
- */
510
- navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
511
-
512
- /**
513
- * @internal
514
- * PRIVATE - DO NOT USE
515
- *
516
- * Trigger a fetcher load/submission
517
- *
518
- * @param key Fetcher key
519
- * @param routeId Route that owns the fetcher
520
- * @param href href to fetch
521
- * @param opts Fetcher options, (method, submission, etc.)
522
- */
523
- fetch(
524
- key: string,
525
- routeId: string,
526
- href: string | null,
527
- opts?: RouterFetchOptions
528
- ): void;
529
-
530
- /**
531
- * @internal
532
- * PRIVATE - DO NOT USE
533
- *
534
- * Trigger a revalidation of all current route loaders and fetcher loads
535
- */
536
- revalidate(): void;
537
-
538
- /**
539
- * @internal
540
- * PRIVATE - DO NOT USE
541
- *
542
- * Utility function to create an href for the given location
543
- * @param location
544
- */
545
- createHref(location: Location | URL): string;
546
-
547
- /**
548
- * @internal
549
- * PRIVATE - DO NOT USE
550
- *
551
- * Utility function to URL encode a destination path according to the internal
552
- * history implementation
553
- * @param to
554
- */
555
- encodeLocation(to: To): Path;
556
-
557
- /**
558
- * @internal
559
- * PRIVATE - DO NOT USE
560
- *
561
- * Get/create a fetcher for the given key
562
- * @param key
563
- */
564
- getFetcher<TData = any>(key: string): Fetcher<TData>;
565
-
566
- /**
567
- * @internal
568
- * PRIVATE - DO NOT USE
569
- *
570
- * Delete the fetcher for a given key
571
- * @param key
572
- */
573
- deleteFetcher(key: string): void;
574
-
575
- /**
576
- * @internal
577
- * PRIVATE - DO NOT USE
578
- *
579
- * Cleanup listeners and abort any in-progress loads
580
- */
581
- dispose(): void;
582
-
583
- /**
584
- * @internal
585
- * PRIVATE - DO NOT USE
586
- *
587
- * Get a navigation blocker
588
- * @param key The identifier for the blocker
589
- * @param fn The blocker function implementation
590
- */
591
- getBlocker(key: string, fn: BlockerFunction): Blocker;
592
-
593
- /**
594
- * @internal
595
- * PRIVATE - DO NOT USE
596
- *
597
- * Delete a navigation blocker
598
- * @param key The identifier for the blocker
599
- */
600
- deleteBlocker(key: string): void;
601
-
602
- /**
603
- * @internal
604
- * PRIVATE DO NOT USE
605
- *
606
- * Patch additional children routes into an existing parent route
607
- * @param routeId The parent route id or a callback function accepting `patch`
608
- * to perform batch patching
609
- * @param children The additional children routes
610
- */
611
- patchRoutes(routeId: string | null, children: AgnosticRouteObject[]): void;
612
-
613
- /**
614
- * @internal
615
- * PRIVATE - DO NOT USE
616
- *
617
- * HMR needs to pass in-flight route updates to React Router
618
- * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
619
- */
620
- _internalSetRoutes(routes: AgnosticRouteObject[]): void;
621
-
622
- /**
623
- * @internal
624
- * PRIVATE - DO NOT USE
625
- *
626
- * Internal fetch AbortControllers accessed by unit tests
627
- */
628
- _internalFetchControllers: Map<string, AbortController>;
629
-
630
- /**
631
- * @internal
632
- * PRIVATE - DO NOT USE
633
- *
634
- * Internal pending DeferredData instances accessed by unit tests
635
- */
636
- _internalActiveDeferreds: Map<string, DeferredData>;
637
- }