@depup/sanity 5.17.1-depup.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/LICENSE +21 -0
- package/README.md +57 -0
- package/bin/sanity +209 -0
- package/changes.json +114 -0
- package/lib/_chunks-dts/ActiveWorkspaceMatcherContext.d.ts +16164 -0
- package/lib/_chunks-dts/index.d.ts +780 -0
- package/lib/_chunks-dts/types.d.ts +2765 -0
- package/lib/_chunks-dts/types2.d.ts +656 -0
- package/lib/_chunks-dts/types3.d.ts +303 -0
- package/lib/_chunks-es/BroadcastDisplayedDocument.js +20 -0
- package/lib/_chunks-es/BroadcastDisplayedDocument.js.map +1 -0
- package/lib/_chunks-es/DisplayedDocumentBroadcaster.js +32 -0
- package/lib/_chunks-es/DisplayedDocumentBroadcaster.js.map +1 -0
- package/lib/_chunks-es/LiveQueries.js +339 -0
- package/lib/_chunks-es/LiveQueries.js.map +1 -0
- package/lib/_chunks-es/MenuGroup.js +106 -0
- package/lib/_chunks-es/MenuGroup.js.map +1 -0
- package/lib/_chunks-es/PostMessageDocuments.js +72 -0
- package/lib/_chunks-es/PostMessageDocuments.js.map +1 -0
- package/lib/_chunks-es/PostMessagePerspective.js +23 -0
- package/lib/_chunks-es/PostMessagePerspective.js.map +1 -0
- package/lib/_chunks-es/PostMessagePreviewSnapshots.js +69 -0
- package/lib/_chunks-es/PostMessagePreviewSnapshots.js.map +1 -0
- package/lib/_chunks-es/PostMessageRefreshMutations.js +74 -0
- package/lib/_chunks-es/PostMessageRefreshMutations.js.map +1 -0
- package/lib/_chunks-es/PostMessageSchema.js +502 -0
- package/lib/_chunks-es/PostMessageSchema.js.map +1 -0
- package/lib/_chunks-es/PostMessageTelemetry.js +21 -0
- package/lib/_chunks-es/PostMessageTelemetry.js.map +1 -0
- package/lib/_chunks-es/PresentationToolGrantsCheck.js +3848 -0
- package/lib/_chunks-es/PresentationToolGrantsCheck.js.map +1 -0
- package/lib/_chunks-es/QRCodeSVG.js +692 -0
- package/lib/_chunks-es/QRCodeSVG.js.map +1 -0
- package/lib/_chunks-es/StructureToolProvider.js +2360 -0
- package/lib/_chunks-es/StructureToolProvider.js.map +1 -0
- package/lib/_chunks-es/VideoPlayer.js +22 -0
- package/lib/_chunks-es/VideoPlayer.js.map +1 -0
- package/lib/_chunks-es/ViteDevServerStopped.js +52 -0
- package/lib/_chunks-es/ViteDevServerStopped.js.map +1 -0
- package/lib/_chunks-es/index.js +285 -0
- package/lib/_chunks-es/index.js.map +1 -0
- package/lib/_chunks-es/index2.js +105 -0
- package/lib/_chunks-es/index2.js.map +1 -0
- package/lib/_chunks-es/index3.js +139 -0
- package/lib/_chunks-es/index3.js.map +1 -0
- package/lib/_chunks-es/index4.js +1020 -0
- package/lib/_chunks-es/index4.js.map +1 -0
- package/lib/_chunks-es/pane.js +5 -0
- package/lib/_chunks-es/pane.js.map +1 -0
- package/lib/_chunks-es/pane2.js +5 -0
- package/lib/_chunks-es/pane2.js.map +1 -0
- package/lib/_chunks-es/presentation.js +549 -0
- package/lib/_chunks-es/presentation.js.map +1 -0
- package/lib/_chunks-es/resources.js +303 -0
- package/lib/_chunks-es/resources.js.map +1 -0
- package/lib/_chunks-es/resources2.js +459 -0
- package/lib/_chunks-es/resources2.js.map +1 -0
- package/lib/_chunks-es/resources3.js +281 -0
- package/lib/_chunks-es/resources3.js.map +1 -0
- package/lib/_chunks-es/resources4.js +184 -0
- package/lib/_chunks-es/resources4.js.map +1 -0
- package/lib/_chunks-es/resources5.js +161 -0
- package/lib/_chunks-es/resources5.js.map +1 -0
- package/lib/_chunks-es/resources6.js +141 -0
- package/lib/_chunks-es/resources6.js.map +1 -0
- package/lib/_chunks-es/resources7.js +24 -0
- package/lib/_chunks-es/resources7.js.map +1 -0
- package/lib/_chunks-es/resources8.js +603 -0
- package/lib/_chunks-es/resources8.js.map +1 -0
- package/lib/_chunks-es/resources9.js +126 -0
- package/lib/_chunks-es/resources9.js.map +1 -0
- package/lib/_chunks-es/structureTool.js +13673 -0
- package/lib/_chunks-es/structureTool.js.map +1 -0
- package/lib/_chunks-es/version.js +17 -0
- package/lib/_chunks-es/version.js.map +1 -0
- package/lib/_createContext.d.ts +12 -0
- package/lib/_createContext.js +38 -0
- package/lib/_createContext.js.map +1 -0
- package/lib/_internal.d.ts +9 -0
- package/lib/_internal.js +12 -0
- package/lib/_internal.js.map +1 -0
- package/lib/_singletons.d.ts +951 -0
- package/lib/_singletons.js +284 -0
- package/lib/_singletons.js.map +1 -0
- package/lib/cli.d.ts +3 -0
- package/lib/cli.js +9 -0
- package/lib/cli.js.map +1 -0
- package/lib/desk.d.ts +910 -0
- package/lib/desk.js +71 -0
- package/lib/desk.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +92934 -0
- package/lib/index.js.map +1 -0
- package/lib/media-library.d.ts +85 -0
- package/lib/media-library.js +11 -0
- package/lib/media-library.js.map +1 -0
- package/lib/migrate.d.ts +1 -0
- package/lib/migrate.js +2 -0
- package/lib/migrate.js.map +1 -0
- package/lib/presentation.d.ts +28 -0
- package/lib/presentation.js +10 -0
- package/lib/presentation.js.map +1 -0
- package/lib/router.d.ts +560 -0
- package/lib/router.js +777 -0
- package/lib/router.js.map +1 -0
- package/lib/structure.d.ts +3 -0
- package/lib/structure.js +639 -0
- package/lib/structure.js.map +1 -0
- package/mock-browser-env-stub-loader.mjs +27 -0
- package/package.json +383 -0
- package/static/favicons/apple-touch-icon.png +0 -0
- package/static/favicons/favicon-192.png +0 -0
- package/static/favicons/favicon-512.png +0 -0
- package/static/favicons/favicon-96.png +0 -0
- package/static/favicons/favicon.ico +0 -0
- package/static/favicons/favicon.svg +12 -0
package/lib/router.d.ts
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import { _ as RouterContextValue, a as MatchError, b as SearchParam, c as NavigateBaseOptions, d as NextStateOrOptions, f as Route, g as Router, h as RouteTransform, i as InternalSearchParam, l as NavigateOptions, m as RouteSegment, n as IntentJsonParams, o as MatchOk, p as RouteChildren, r as IntentParameters, s as MatchResult, t as BaseIntentParams, u as NavigateOptionsWithState, v as RouterNode, y as RouterState } from "./_chunks-dts/types3.js";
|
|
2
|
+
import * as react from "react";
|
|
3
|
+
import { ComponentType, FunctionComponent, HTMLProps, MouseEventHandler, ReactNode } from "react";
|
|
4
|
+
import { RouterContext } from "sanity/_singletons";
|
|
5
|
+
/**
|
|
6
|
+
* Props for the {@link IntentLink} component.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
interface IntentLinkProps {
|
|
11
|
+
/**
|
|
12
|
+
* The name of the intent.
|
|
13
|
+
*/
|
|
14
|
+
intent: string;
|
|
15
|
+
/**
|
|
16
|
+
* The parameters to include in the intent.
|
|
17
|
+
* {@link IntentParameters}
|
|
18
|
+
*/
|
|
19
|
+
params?: IntentParameters;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to replace the current URL in the browser history instead of adding a new entry.
|
|
22
|
+
*/
|
|
23
|
+
replace?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* search params to include in the intent.
|
|
26
|
+
*/
|
|
27
|
+
searchParams?: SearchParam[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @public
|
|
31
|
+
*
|
|
32
|
+
* @param props - Props to pass to `IntentLink` component.
|
|
33
|
+
* See {@link IntentLinkProps}
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* function MyComponent() {
|
|
38
|
+
* return <IntentLink intent="edit" params={{id: 'abc123'}}>Edit</IntentLink>
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare const IntentLink: react.ForwardRefExoticComponent<Omit<IntentLinkProps & HTMLProps<HTMLAnchorElement>, "ref"> & react.RefAttributes<HTMLAnchorElement>>;
|
|
43
|
+
/**
|
|
44
|
+
* Props for the {@link Link} component.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
interface LinkProps {
|
|
49
|
+
/**
|
|
50
|
+
* Whether to replace the current URL in the browser history instead of adding a new entry.
|
|
51
|
+
*/
|
|
52
|
+
replace?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A component that creates an HTML anchor element.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*
|
|
59
|
+
* @param props - Props to pass to the `Link` component.
|
|
60
|
+
* See {@link LinkProps}
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* function MyComponent() {
|
|
65
|
+
* return (
|
|
66
|
+
* <Link href="https://www.sanity.io" target="_blank" replace>
|
|
67
|
+
* Go to Sanity
|
|
68
|
+
* </Link>
|
|
69
|
+
* )
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare const Link: react.ForwardRefExoticComponent<Omit<LinkProps & HTMLProps<HTMLAnchorElement>, "ref"> & react.RefAttributes<HTMLAnchorElement>>;
|
|
74
|
+
/**
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
interface RouteNodeOptions {
|
|
78
|
+
/**
|
|
79
|
+
* The path of the route node.
|
|
80
|
+
*/
|
|
81
|
+
path?: string;
|
|
82
|
+
/**
|
|
83
|
+
* The children of the route node. See {@link RouteChildren}
|
|
84
|
+
*/
|
|
85
|
+
children?: RouteChildren;
|
|
86
|
+
/**
|
|
87
|
+
* The transforms to apply to the route node. See {@link RouteTransform}
|
|
88
|
+
*/
|
|
89
|
+
transform?: {
|
|
90
|
+
[key: string]: RouteTransform<any>;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The scope of the route node.
|
|
94
|
+
*/
|
|
95
|
+
scope?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Optionally disable scoping of search params
|
|
98
|
+
* Scoped search params will be represented as scope[param]=value in the url
|
|
99
|
+
* Disabling this will still scope search params based on any parent scope unless the parent scope also has disabled search params scoping
|
|
100
|
+
* Caution: enabling this can cause conflicts with multiple plugins defining search params with the same name
|
|
101
|
+
*/
|
|
102
|
+
__unsafe_disableScopedSearchParams?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Interface for the {@link route} object.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
interface RouteObject {
|
|
110
|
+
/**
|
|
111
|
+
* Creates a new router.
|
|
112
|
+
* Returns {@link Router}
|
|
113
|
+
* See {@link RouteNodeOptions} and {@link RouteChildren}
|
|
114
|
+
*/
|
|
115
|
+
create: (routeOrOpts: RouteNodeOptions | string, childrenOrOpts?: RouteNodeOptions | RouteChildren | null, children?: Router | RouteChildren) => Router;
|
|
116
|
+
/**
|
|
117
|
+
* Creates a new router for handling intents.
|
|
118
|
+
* Returns {@link Router}
|
|
119
|
+
*/
|
|
120
|
+
intents: (base: string) => Router;
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new router scope.
|
|
123
|
+
* Returns {@link Router}
|
|
124
|
+
*/
|
|
125
|
+
scope(scopeName: string, routeOrOpts: RouteNodeOptions | string, childrenOrOpts?: RouteNodeOptions | RouteChildren | null, children?: Router | RouteChildren): Router;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* An object containing functions for creating routers and router scopes.
|
|
129
|
+
* See {@link RouteObject}
|
|
130
|
+
*
|
|
131
|
+
* @public
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* const router = route.create({
|
|
136
|
+
* path: "/foo",
|
|
137
|
+
* children: [
|
|
138
|
+
* route.create({
|
|
139
|
+
* path: "/bar",
|
|
140
|
+
* children: [
|
|
141
|
+
* route.create({
|
|
142
|
+
* path: "/:baz",
|
|
143
|
+
* transform: {
|
|
144
|
+
* baz: {
|
|
145
|
+
* toState: (id) => ({ id }),
|
|
146
|
+
* toPath: (state) => state.id,
|
|
147
|
+
* },
|
|
148
|
+
* },
|
|
149
|
+
* }),
|
|
150
|
+
* ],
|
|
151
|
+
* }),
|
|
152
|
+
* ],
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare const route: RouteObject;
|
|
157
|
+
/**
|
|
158
|
+
* @internal
|
|
159
|
+
* @param options - Route node options
|
|
160
|
+
*/
|
|
161
|
+
declare function _createNode(options: RouteNodeOptions): Router;
|
|
162
|
+
/**
|
|
163
|
+
* The props for the {@link RouterProvider} component.
|
|
164
|
+
*
|
|
165
|
+
* @public
|
|
166
|
+
*/
|
|
167
|
+
interface RouterProviderProps {
|
|
168
|
+
/**
|
|
169
|
+
* A function that is called when the user navigates to a new path.
|
|
170
|
+
* Takes an object containing the path to navigate to and an optional `replace` flag.
|
|
171
|
+
*/
|
|
172
|
+
onNavigate: (opts: {
|
|
173
|
+
path: string;
|
|
174
|
+
replace?: boolean;
|
|
175
|
+
}) => void;
|
|
176
|
+
/**
|
|
177
|
+
* The router object that is used to handle navigation. See {@link Router}
|
|
178
|
+
*/
|
|
179
|
+
router: Router;
|
|
180
|
+
/**
|
|
181
|
+
* The current state of the router. See {@link RouterState}
|
|
182
|
+
*/
|
|
183
|
+
state: RouterState;
|
|
184
|
+
/**
|
|
185
|
+
* The child elements to render.
|
|
186
|
+
*/
|
|
187
|
+
children: ReactNode;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* @example
|
|
191
|
+
* ```tsx
|
|
192
|
+
* import {
|
|
193
|
+
* NavigateOptions,
|
|
194
|
+
* route,
|
|
195
|
+
* RouterProvider,
|
|
196
|
+
* RouterState
|
|
197
|
+
* } from 'sanity'
|
|
198
|
+
* import {useCallback, useMemo} from 'react'
|
|
199
|
+
*
|
|
200
|
+
* function Root() {
|
|
201
|
+
* const [router] = useState(() => route.create('/'))
|
|
202
|
+
*
|
|
203
|
+
* const [state, setState] = useState<RouterState>({})
|
|
204
|
+
*
|
|
205
|
+
* const handleNavigate = useCallback((
|
|
206
|
+
* path: string,
|
|
207
|
+
* options?: NavigateOptions
|
|
208
|
+
* ) => {
|
|
209
|
+
* console.log('navigate', path, options)
|
|
210
|
+
*
|
|
211
|
+
* setState(router.decode(path))
|
|
212
|
+
* }, [router])
|
|
213
|
+
*
|
|
214
|
+
* return (
|
|
215
|
+
* <RouterProvider
|
|
216
|
+
* onNavigate={handleNavigate}
|
|
217
|
+
* router={router}
|
|
218
|
+
* state={state}
|
|
219
|
+
* >
|
|
220
|
+
* <div>This is a routed application</div>
|
|
221
|
+
* </RouterProvider>
|
|
222
|
+
* )
|
|
223
|
+
* }
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @param props - The component props.
|
|
227
|
+
* {@link RouterProviderProps}
|
|
228
|
+
*
|
|
229
|
+
* @public
|
|
230
|
+
*/
|
|
231
|
+
declare function RouterProvider(props: RouterProviderProps): React.JSX.Element;
|
|
232
|
+
/**
|
|
233
|
+
* Props for the {@link RouteScope} component.
|
|
234
|
+
*
|
|
235
|
+
* @public
|
|
236
|
+
*/
|
|
237
|
+
interface RouteScopeProps {
|
|
238
|
+
/**
|
|
239
|
+
* The scope for the nested routes.
|
|
240
|
+
*/
|
|
241
|
+
scope: string;
|
|
242
|
+
/**
|
|
243
|
+
* Optionally disable scoping of search params
|
|
244
|
+
* Scoped search params will be represented as scope[param]=value in the url
|
|
245
|
+
* Disabling this will still scope search params based on any parent scope unless the parent scope also has disabled search params scoping
|
|
246
|
+
* Caution: enabling this can cause conflicts with multiple plugins defining search params with the same name
|
|
247
|
+
*/
|
|
248
|
+
__unsafe_disableScopedSearchParams?: boolean;
|
|
249
|
+
/**
|
|
250
|
+
* The content to display inside the route scope.
|
|
251
|
+
*/
|
|
252
|
+
children: ReactNode;
|
|
253
|
+
}
|
|
254
|
+
declare function RouteScope(props: RouteScopeProps): React.JSX.Element;
|
|
255
|
+
declare namespace RouteScope {
|
|
256
|
+
var displayName: string;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Props for the {@link StateLink} component.
|
|
260
|
+
*
|
|
261
|
+
* @public
|
|
262
|
+
*/
|
|
263
|
+
interface StateLinkProps {
|
|
264
|
+
/**
|
|
265
|
+
* Whether to replace the current history entry instead of adding a new one.
|
|
266
|
+
*/
|
|
267
|
+
replace?: boolean;
|
|
268
|
+
/**
|
|
269
|
+
* The state to associate with the link.
|
|
270
|
+
*/
|
|
271
|
+
state?: Record<string, unknown>;
|
|
272
|
+
/**
|
|
273
|
+
* Whether to navigate to the index page of the app.
|
|
274
|
+
*/
|
|
275
|
+
toIndex?: boolean;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* A component that creates a link that updates the URL state.
|
|
279
|
+
*
|
|
280
|
+
* @remarks
|
|
281
|
+
* This component uses the {@link useStateLink} hook
|
|
282
|
+
* to create a link that updates the URL state.
|
|
283
|
+
*
|
|
284
|
+
* @param props - Props to pass to the `StateLink` component.
|
|
285
|
+
* See {@link StateLinkProps}.
|
|
286
|
+
*
|
|
287
|
+
* @public
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```tsx
|
|
291
|
+
* function MyComponent() {
|
|
292
|
+
* return <StateLink state={{foo: 'bar'}}>Link</StateLink>
|
|
293
|
+
* }
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
declare const StateLink: react.ForwardRefExoticComponent<Omit<StateLinkProps & Omit<HTMLProps<HTMLAnchorElement>, "href">, "ref"> & react.RefAttributes<HTMLAnchorElement>>;
|
|
297
|
+
/**
|
|
298
|
+
* @internal
|
|
299
|
+
*/
|
|
300
|
+
declare const STICKY_PARAMS: string[];
|
|
301
|
+
/**
|
|
302
|
+
* @public
|
|
303
|
+
*/
|
|
304
|
+
interface UseIntentLinkOptions {
|
|
305
|
+
/**
|
|
306
|
+
* The name of the intent to trigger.
|
|
307
|
+
*/
|
|
308
|
+
intent: string;
|
|
309
|
+
/**
|
|
310
|
+
* An optional click event handler.
|
|
311
|
+
*/
|
|
312
|
+
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
313
|
+
/**
|
|
314
|
+
* Optional parameters to pass to the intent. See {@link IntentParameters}
|
|
315
|
+
*/
|
|
316
|
+
params?: IntentParameters;
|
|
317
|
+
/**
|
|
318
|
+
* Whether to replace the current URL in the browser history.
|
|
319
|
+
*/
|
|
320
|
+
replace?: boolean;
|
|
321
|
+
/**
|
|
322
|
+
* The target window or frame to open the link in.
|
|
323
|
+
*/
|
|
324
|
+
target?: string;
|
|
325
|
+
searchParams?: SearchParam[];
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
*
|
|
329
|
+
* Returns props for an anchor element that will trigger an intent when clicked.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```tsx
|
|
333
|
+
* const {onClick, href} = useIntentLink({
|
|
334
|
+
* intent: 'edit',
|
|
335
|
+
* params: {id: 'foo'}
|
|
336
|
+
* })
|
|
337
|
+
*
|
|
338
|
+
* <a href={href} onClick={onClick}>Link to "foo" editor</a>
|
|
339
|
+
* ```
|
|
340
|
+
*
|
|
341
|
+
* @public
|
|
342
|
+
*
|
|
343
|
+
* @param options - Options to use for the link
|
|
344
|
+
* {@link UseIntentLinkOptions}
|
|
345
|
+
*
|
|
346
|
+
* @returns - An object with `onClick` and `href` props to use for the link
|
|
347
|
+
*/
|
|
348
|
+
declare function useIntentLink(options: UseIntentLinkOptions): {
|
|
349
|
+
onClick: React.MouseEventHandler<HTMLElement>;
|
|
350
|
+
href: string;
|
|
351
|
+
};
|
|
352
|
+
/**
|
|
353
|
+
* @public
|
|
354
|
+
*/
|
|
355
|
+
interface UseLinkOptions {
|
|
356
|
+
/**
|
|
357
|
+
* The URL that the link should navigate to.
|
|
358
|
+
*/
|
|
359
|
+
href?: string;
|
|
360
|
+
/**
|
|
361
|
+
* The event handler function that should be called when the link is clicked.
|
|
362
|
+
*/
|
|
363
|
+
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
364
|
+
/**
|
|
365
|
+
* Whether the link should replace the current URL in the browser history.
|
|
366
|
+
*/
|
|
367
|
+
replace?: boolean;
|
|
368
|
+
/**
|
|
369
|
+
* The target window or frame that the linked document will open in.
|
|
370
|
+
*/
|
|
371
|
+
target?: string;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Returns an object with an `onClick` function that can be used as a click handler for a link.
|
|
375
|
+
*
|
|
376
|
+
* @public
|
|
377
|
+
*
|
|
378
|
+
* @param options - An object containing the properties for the link.
|
|
379
|
+
* See {@link UseLinkOptions}
|
|
380
|
+
*
|
|
381
|
+
* @returns An object with an `onClick` function.
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```tsx
|
|
385
|
+
* const linkProps = useLink({
|
|
386
|
+
* href: 'https://www.sanity.io',
|
|
387
|
+
* target: '_blank'
|
|
388
|
+
* })
|
|
389
|
+
*
|
|
390
|
+
* <a {...linkProps}>Link</a>
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
declare function useLink(options: UseLinkOptions): {
|
|
394
|
+
onClick: React.MouseEventHandler<HTMLElement>;
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Returns the router context value.
|
|
398
|
+
* @public
|
|
399
|
+
*
|
|
400
|
+
* @returns The router context value.
|
|
401
|
+
* {@link RouterContextValue}
|
|
402
|
+
* @throws An error if the router context value is missing.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```tsx
|
|
406
|
+
* const router = useRouter()
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
declare function useRouter(): RouterContextValue;
|
|
410
|
+
/**
|
|
411
|
+
* @public
|
|
412
|
+
*
|
|
413
|
+
* @param selector - A selector function that receives the router state and returns a value. See {@link RouterState}
|
|
414
|
+
*
|
|
415
|
+
* @returns The value returned by the selector function or RouterState. See {@link RouterState}
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```tsx
|
|
419
|
+
* const {activeTool} = useRouterState(state => state.tool)
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
declare function useRouterState<R = RouterState>(selector: (routerState: RouterState) => R): R;
|
|
423
|
+
/**
|
|
424
|
+
* @public
|
|
425
|
+
*
|
|
426
|
+
* @returns The router state. See {@link RouterState}
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```tsx
|
|
430
|
+
* const routerState = useRouterState()
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
declare function useRouterState(): RouterState;
|
|
434
|
+
/**
|
|
435
|
+
* @public
|
|
436
|
+
*/
|
|
437
|
+
interface UseStateLinkOptions {
|
|
438
|
+
/**
|
|
439
|
+
* The click event handler for the link.
|
|
440
|
+
*/
|
|
441
|
+
onClick?: MouseEventHandler<HTMLElement>;
|
|
442
|
+
/**
|
|
443
|
+
* Whether to replace the current history entry instead of adding a new one.
|
|
444
|
+
*/
|
|
445
|
+
replace?: boolean;
|
|
446
|
+
/**
|
|
447
|
+
* The state object to update when the link is clicked.
|
|
448
|
+
*/
|
|
449
|
+
state?: Record<string, unknown>;
|
|
450
|
+
/**
|
|
451
|
+
* The target window or frame to open the linked document in.
|
|
452
|
+
*/
|
|
453
|
+
target?: string;
|
|
454
|
+
/**
|
|
455
|
+
* Whether to navigate to the index page of the linked document.
|
|
456
|
+
*/
|
|
457
|
+
toIndex?: boolean;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* @public
|
|
461
|
+
*
|
|
462
|
+
* @param options - Options to use for the link
|
|
463
|
+
* {@link UseStateLinkOptions}
|
|
464
|
+
*
|
|
465
|
+
* @returns - An object with `onClick` and `href` props to use for the link
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* ```tsx
|
|
469
|
+
* const {onClick, href} = useStateLink({state: {foo: 'bar'}})
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
declare function useStateLink(options: UseStateLinkOptions): {
|
|
473
|
+
onClick: MouseEventHandler<HTMLElement>;
|
|
474
|
+
href: string;
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* Decode a path segment containing JSON parameters
|
|
478
|
+
*
|
|
479
|
+
* @param pathSegment - The path segment to decode
|
|
480
|
+
* @returns The decoded parameters
|
|
481
|
+
* @internal
|
|
482
|
+
* @hidden
|
|
483
|
+
*/
|
|
484
|
+
declare function decodeJsonParams(pathSegment?: string): any;
|
|
485
|
+
/**
|
|
486
|
+
* Encodes a set of parameters as a path segment, using base64url
|
|
487
|
+
*
|
|
488
|
+
* @param params - Paramters to encode
|
|
489
|
+
* @returns The encoded parameters as a path segment
|
|
490
|
+
* @internal
|
|
491
|
+
* @hidden
|
|
492
|
+
*/
|
|
493
|
+
declare function encodeJsonParams(params?: any): string;
|
|
494
|
+
/**
|
|
495
|
+
* A higher-order component that injects the `router` object from the `useRouter` hook
|
|
496
|
+
* into the props of the wrapped component.
|
|
497
|
+
*
|
|
498
|
+
* @internal
|
|
499
|
+
* @deprecated - Use the `useRouter` hook instead.
|
|
500
|
+
*
|
|
501
|
+
* @param Component - The component to wrap.
|
|
502
|
+
*
|
|
503
|
+
* @returns The wrapped component.
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ```tsx
|
|
507
|
+
* function MyComponent(props) {
|
|
508
|
+
* return <div>{props.router.state.myParam}</div>
|
|
509
|
+
* }
|
|
510
|
+
*
|
|
511
|
+
* export default withRouter(MyComponent)
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
declare function withRouter<Props extends {
|
|
515
|
+
router: RouterContextValue;
|
|
516
|
+
}>(Component: ComponentType<Props>): FunctionComponent<Omit<Props, 'router'>>;
|
|
517
|
+
/**
|
|
518
|
+
* @internal
|
|
519
|
+
* @deprecated - Use the `useRouter` hook instead.
|
|
520
|
+
*/
|
|
521
|
+
interface WithRouterProps {
|
|
522
|
+
/**
|
|
523
|
+
* The `router` object from the `useRouter` hook.
|
|
524
|
+
* {@link RouterContextValue}
|
|
525
|
+
*/
|
|
526
|
+
router: RouterContextValue;
|
|
527
|
+
/**
|
|
528
|
+
* A function that renders the wrapped component with the `router` object as a parameter.
|
|
529
|
+
*/
|
|
530
|
+
children: (router: RouterContextValue) => React.JSX.Element;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* A higher-order component that injects the router object into its child component.
|
|
534
|
+
*
|
|
535
|
+
* @internal
|
|
536
|
+
* @deprecated - Use the `useRouter` hook instead.
|
|
537
|
+
*
|
|
538
|
+
* @returns The rendered component.
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* ```tsx
|
|
542
|
+
* function MyComponent(props: {router: Router}) {
|
|
543
|
+
* const {location} = props.router
|
|
544
|
+
* const {pathname} = location
|
|
545
|
+
* return <p>The current path is: {pathname}</p>
|
|
546
|
+
* }
|
|
547
|
+
*
|
|
548
|
+
* function App() {
|
|
549
|
+
* return (
|
|
550
|
+
* <Router>
|
|
551
|
+
* <WithRouter>
|
|
552
|
+
* {router => <MyComponent router={router} />}
|
|
553
|
+
* </WithRouter>
|
|
554
|
+
* </Router>
|
|
555
|
+
* )
|
|
556
|
+
* }
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
559
|
+
declare const WithRouter: FunctionComponent<Omit<WithRouterProps, "router">>;
|
|
560
|
+
export { type BaseIntentParams, type IntentJsonParams, IntentLink, IntentLinkProps, type IntentParameters, type InternalSearchParam, Link, LinkProps, type MatchError, type MatchOk, type MatchResult, type NavigateBaseOptions, type NavigateOptions, type NavigateOptionsWithState, type NextStateOrOptions, type Route, type RouteChildren, RouteNodeOptions, RouteObject, RouteScope, RouteScopeProps, type RouteSegment, type RouteTransform, type Router, RouterContext, type RouterContextValue, type RouterNode, RouterProvider, RouterProviderProps, type RouterState, STICKY_PARAMS, type SearchParam, StateLink, StateLinkProps, UseIntentLinkOptions, UseLinkOptions, UseStateLinkOptions, WithRouter, WithRouterProps, _createNode, decodeJsonParams, encodeJsonParams, route, useIntentLink, useLink, useRouter, useRouterState, useStateLink, withRouter };
|