@kestack/kabuki 0.0.0 → 0.0.2

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.
Files changed (234) hide show
  1. package/README.md +156 -33
  2. package/dist/core/actor/actor.d.ts +24 -13
  3. package/dist/core/actor/actor.d.ts.map +1 -1
  4. package/dist/core/actor/actor.js +37 -26
  5. package/dist/core/actor/index.d.ts +2 -2
  6. package/dist/core/actor/index.d.ts.map +1 -1
  7. package/dist/core/actor/types.d.ts +91 -47
  8. package/dist/core/actor/types.d.ts.map +1 -1
  9. package/dist/core/history/history.d.ts +11 -3
  10. package/dist/core/history/history.d.ts.map +1 -1
  11. package/dist/core/history/history.js +106 -27
  12. package/dist/core/history/replay.d.ts +2 -0
  13. package/dist/core/history/replay.d.ts.map +1 -1
  14. package/dist/core/history/replay.js +1 -0
  15. package/dist/core/history/saved.d.ts +1 -1
  16. package/dist/core/history/saved.d.ts.map +1 -1
  17. package/dist/core/history/saved.js +13 -9
  18. package/dist/core/index.d.ts +1 -1
  19. package/dist/core/index.d.ts.map +1 -1
  20. package/dist/core/snapshot/invoke.d.ts +2 -3
  21. package/dist/core/snapshot/invoke.d.ts.map +1 -1
  22. package/dist/core/snapshot/invoke.js +42 -49
  23. package/dist/core/snapshot/restore.js +8 -7
  24. package/dist/core/snapshot/tree.d.ts +1 -1
  25. package/dist/core/snapshot/tree.d.ts.map +1 -1
  26. package/dist/core/snapshot/tree.js +1 -1
  27. package/dist/react/app.d.ts +30 -3
  28. package/dist/react/app.d.ts.map +1 -1
  29. package/dist/react/app.js +119 -40
  30. package/dist/react/drawn.d.ts +1 -1
  31. package/dist/react/drawn.d.ts.map +1 -1
  32. package/dist/react/drawn.js +2 -1
  33. package/dist/react/index.d.ts +3 -0
  34. package/dist/react/index.d.ts.map +1 -1
  35. package/dist/react/index.js +2 -0
  36. package/dist/react/lazy.d.ts +30 -0
  37. package/dist/react/lazy.d.ts.map +1 -0
  38. package/dist/react/lazy.js +56 -0
  39. package/dist/react/live.d.ts +7 -0
  40. package/dist/react/live.d.ts.map +1 -0
  41. package/dist/react/live.js +13 -0
  42. package/dist/react/view.d.ts +26 -6
  43. package/dist/react/view.d.ts.map +1 -1
  44. package/dist/react/view.js +17 -5
  45. package/dist/routing/adapter/adapter.d.ts +38 -0
  46. package/dist/routing/adapter/adapter.d.ts.map +1 -0
  47. package/dist/routing/adapter/adapter.js +10 -0
  48. package/dist/routing/adapter/browser/browser.d.ts +8 -0
  49. package/dist/routing/adapter/browser/browser.d.ts.map +1 -0
  50. package/dist/routing/adapter/browser/browser.js +33 -0
  51. package/dist/routing/adapter/browser/index.d.ts +2 -0
  52. package/dist/routing/adapter/browser/index.d.ts.map +1 -0
  53. package/dist/routing/adapter/browser/index.js +1 -0
  54. package/dist/routing/adapter/index.d.ts +3 -0
  55. package/dist/routing/adapter/index.d.ts.map +1 -0
  56. package/dist/routing/adapter/index.js +1 -0
  57. package/dist/routing/adapter/tanstack/index.d.ts +3 -0
  58. package/dist/routing/adapter/tanstack/index.d.ts.map +1 -0
  59. package/dist/routing/adapter/tanstack/index.js +1 -0
  60. package/dist/routing/adapter/tanstack/tanstack.d.ts +27 -0
  61. package/dist/routing/adapter/tanstack/tanstack.d.ts.map +1 -0
  62. package/dist/routing/adapter/tanstack/tanstack.js +38 -0
  63. package/dist/routing/capability/cache.d.ts +12 -0
  64. package/dist/routing/capability/cache.d.ts.map +1 -0
  65. package/dist/routing/capability/cache.js +170 -0
  66. package/dist/routing/capability/index.d.ts +6 -0
  67. package/dist/routing/capability/index.d.ts.map +1 -0
  68. package/dist/routing/capability/index.js +3 -0
  69. package/dist/routing/capability/loading.d.ts +82 -0
  70. package/dist/routing/capability/loading.d.ts.map +1 -0
  71. package/dist/routing/capability/loading.js +53 -0
  72. package/dist/routing/capability/navigation.d.ts +66 -0
  73. package/dist/routing/capability/navigation.d.ts.map +1 -0
  74. package/dist/routing/capability/navigation.js +65 -0
  75. package/dist/routing/index.d.ts +10 -0
  76. package/dist/routing/index.d.ts.map +1 -0
  77. package/dist/routing/index.js +4 -0
  78. package/dist/routing/page/index.d.ts +5 -0
  79. package/dist/routing/page/index.d.ts.map +1 -0
  80. package/dist/routing/page/index.js +2 -0
  81. package/dist/routing/page/page.d.ts +151 -0
  82. package/dist/routing/page/page.d.ts.map +1 -0
  83. package/dist/routing/page/page.js +121 -0
  84. package/dist/routing/page/status.d.ts +121 -0
  85. package/dist/routing/page/status.d.ts.map +1 -0
  86. package/dist/routing/page/status.js +69 -0
  87. package/dist/routing/route/index.d.ts +11 -0
  88. package/dist/routing/route/index.d.ts.map +1 -0
  89. package/dist/routing/route/index.js +6 -0
  90. package/dist/routing/route/loader.d.ts +98 -0
  91. package/dist/routing/route/loader.d.ts.map +1 -0
  92. package/dist/routing/route/loader.js +17 -0
  93. package/dist/routing/route/metadata.d.ts +44 -0
  94. package/dist/routing/route/metadata.d.ts.map +1 -0
  95. package/dist/routing/route/metadata.js +53 -0
  96. package/dist/routing/route/node.d.ts +162 -0
  97. package/dist/routing/route/node.d.ts.map +1 -0
  98. package/dist/routing/route/node.js +3 -0
  99. package/dist/routing/route/places.d.ts +15 -0
  100. package/dist/routing/route/places.d.ts.map +1 -0
  101. package/dist/routing/route/places.js +87 -0
  102. package/dist/routing/route/route.d.ts +53 -0
  103. package/dist/routing/route/route.d.ts.map +1 -0
  104. package/dist/routing/route/route.js +148 -0
  105. package/dist/routing/route/url.d.ts +13 -0
  106. package/dist/routing/route/url.d.ts.map +1 -0
  107. package/dist/routing/route/url.js +79 -0
  108. package/dist/routing/route/values.d.ts +12 -0
  109. package/dist/routing/route/values.d.ts.map +1 -0
  110. package/dist/routing/route/values.js +47 -0
  111. package/dist/routing/router/context.d.ts +123 -0
  112. package/dist/routing/router/context.d.ts.map +1 -0
  113. package/dist/routing/router/context.js +156 -0
  114. package/dist/routing/router/data.d.ts +117 -0
  115. package/dist/routing/router/data.d.ts.map +1 -0
  116. package/dist/routing/router/data.js +247 -0
  117. package/dist/routing/router/define.d.ts +52 -0
  118. package/dist/routing/router/define.d.ts.map +1 -0
  119. package/dist/routing/router/define.js +48 -0
  120. package/dist/routing/router/frame.d.ts +10 -0
  121. package/dist/routing/router/frame.d.ts.map +1 -0
  122. package/dist/routing/router/frame.js +10 -0
  123. package/dist/routing/router/index.d.ts +7 -0
  124. package/dist/routing/router/index.d.ts.map +1 -0
  125. package/dist/routing/router/index.js +3 -0
  126. package/dist/routing/router/router.d.ts +165 -0
  127. package/dist/routing/router/router.d.ts.map +1 -0
  128. package/dist/routing/router/router.js +801 -0
  129. package/dist/routing/routing.d.ts +72 -0
  130. package/dist/routing/routing.d.ts.map +1 -0
  131. package/dist/routing/routing.js +53 -0
  132. package/dist/routing/scroll/index.d.ts +4 -0
  133. package/dist/routing/scroll/index.d.ts.map +1 -0
  134. package/dist/routing/scroll/index.js +2 -0
  135. package/dist/routing/scroll/script.d.ts +6 -0
  136. package/dist/routing/scroll/script.d.ts.map +1 -0
  137. package/dist/routing/scroll/script.js +52 -0
  138. package/dist/routing/scroll/scroll.d.ts +75 -0
  139. package/dist/routing/scroll/scroll.d.ts.map +1 -0
  140. package/dist/routing/scroll/scroll.js +201 -0
  141. package/dist/routing/scroll/selector.d.ts +14 -0
  142. package/dist/routing/scroll/selector.d.ts.map +1 -0
  143. package/dist/routing/scroll/selector.js +40 -0
  144. package/dist/routing/scroll/session.d.ts +6 -0
  145. package/dist/routing/scroll/session.d.ts.map +1 -0
  146. package/dist/routing/scroll/session.js +23 -0
  147. package/dist/start/client/client.d.ts +11 -0
  148. package/dist/start/client/client.d.ts.map +1 -0
  149. package/dist/start/client/client.js +24 -0
  150. package/dist/start/client/index.d.ts +3 -0
  151. package/dist/start/client/index.d.ts.map +1 -0
  152. package/dist/start/client/index.js +2 -0
  153. package/dist/start/client/rpc.d.ts +14 -0
  154. package/dist/start/client/rpc.d.ts.map +1 -0
  155. package/dist/start/client/rpc.js +70 -0
  156. package/dist/start/common/app.d.ts +66 -0
  157. package/dist/start/common/app.d.ts.map +1 -0
  158. package/dist/start/common/app.js +23 -0
  159. package/dist/start/common/common.d.ts +26 -0
  160. package/dist/start/common/common.d.ts.map +1 -0
  161. package/dist/start/common/common.js +19 -0
  162. package/dist/start/common/document.d.ts +44 -0
  163. package/dist/start/common/document.d.ts.map +1 -0
  164. package/dist/start/common/document.js +58 -0
  165. package/dist/start/common/index.d.ts +9 -0
  166. package/dist/start/common/index.d.ts.map +1 -0
  167. package/dist/start/common/index.js +5 -0
  168. package/dist/start/common/page.d.ts +67 -0
  169. package/dist/start/common/page.d.ts.map +1 -0
  170. package/dist/start/common/page.js +29 -0
  171. package/dist/start/common/wire.d.ts +37 -0
  172. package/dist/start/common/wire.d.ts.map +1 -0
  173. package/dist/start/common/wire.js +73 -0
  174. package/dist/start/platform/cloudflare/cloudflare.d.ts +8 -0
  175. package/dist/start/platform/cloudflare/cloudflare.d.ts.map +1 -0
  176. package/dist/start/platform/cloudflare/cloudflare.js +31 -0
  177. package/dist/start/platform/cloudflare/index.d.ts +2 -0
  178. package/dist/start/platform/cloudflare/index.d.ts.map +1 -0
  179. package/dist/start/platform/cloudflare/index.js +1 -0
  180. package/dist/start/platform/index.d.ts +2 -0
  181. package/dist/start/platform/index.d.ts.map +1 -0
  182. package/dist/start/platform/index.js +1 -0
  183. package/dist/start/platform/platform.d.ts +31 -0
  184. package/dist/start/platform/platform.d.ts.map +1 -0
  185. package/dist/start/platform/platform.js +13 -0
  186. package/dist/start/server/cache.d.ts +4 -0
  187. package/dist/start/server/cache.d.ts.map +1 -0
  188. package/dist/start/server/cache.js +26 -0
  189. package/dist/start/server/draw.d.ts +10 -0
  190. package/dist/start/server/draw.d.ts.map +1 -0
  191. package/dist/start/server/draw.js +75 -0
  192. package/dist/start/server/index.d.ts +3 -0
  193. package/dist/start/server/index.d.ts.map +1 -0
  194. package/dist/start/server/index.js +2 -0
  195. package/dist/start/server/layers.d.ts +97 -0
  196. package/dist/start/server/layers.d.ts.map +1 -0
  197. package/dist/start/server/layers.js +37 -0
  198. package/dist/start/server/respond.d.ts +15 -0
  199. package/dist/start/server/respond.d.ts.map +1 -0
  200. package/dist/start/server/respond.js +35 -0
  201. package/dist/start/server/rpc.d.ts +11 -0
  202. package/dist/start/server/rpc.d.ts.map +1 -0
  203. package/dist/start/server/rpc.js +51 -0
  204. package/dist/start/server/server.d.ts +13 -0
  205. package/dist/start/server/server.d.ts.map +1 -0
  206. package/dist/start/server/server.js +138 -0
  207. package/dist/start/server/tiers.d.ts +14 -0
  208. package/dist/start/server/tiers.d.ts.map +1 -0
  209. package/dist/start/server/tiers.js +31 -0
  210. package/dist/start/vite/dev.d.ts +5 -0
  211. package/dist/start/vite/dev.d.ts.map +1 -0
  212. package/dist/start/vite/dev.js +56 -0
  213. package/dist/start/vite/entries.d.ts +27 -0
  214. package/dist/start/vite/entries.d.ts.map +1 -0
  215. package/dist/start/vite/entries.js +66 -0
  216. package/dist/start/vite/files.d.ts +22 -0
  217. package/dist/start/vite/files.d.ts.map +1 -0
  218. package/dist/start/vite/files.js +23 -0
  219. package/dist/start/vite/index.d.ts +2 -0
  220. package/dist/start/vite/index.d.ts.map +1 -0
  221. package/dist/start/vite/index.js +1 -0
  222. package/dist/start/vite/lazy.d.ts +4 -0
  223. package/dist/start/vite/lazy.d.ts.map +1 -0
  224. package/dist/start/vite/lazy.js +30 -0
  225. package/dist/start/vite/manifest.d.ts +18 -0
  226. package/dist/start/vite/manifest.d.ts.map +1 -0
  227. package/dist/start/vite/manifest.js +42 -0
  228. package/dist/start/vite/styles.d.ts +7 -0
  229. package/dist/start/vite/styles.d.ts.map +1 -0
  230. package/dist/start/vite/styles.js +58 -0
  231. package/dist/start/vite/vite.d.ts +11 -0
  232. package/dist/start/vite/vite.d.ts.map +1 -0
  233. package/dist/start/vite/vite.js +217 -0
  234. package/package.json +53 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"places.d.ts","sourceRoot":"","sources":["../../../src/routing/route/places.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EACV,OAAO,EACP,QAAQ,EAER,MAAM,EACN,KAAK,EACL,WAAW,EACX,KAAK,EACN,MAAM,WAAW,CAAC;AASnB,sFAAsF;AACtF,eAAO,MAAM,QAAQ,aACT,QAAQ,SACX,KAAK,cACA,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,KACtC,aAAa,CAAC,KAAK,CA0BrB,CAAC;AAEF,kFAAkF;AAClF,eAAO,MAAM,OAAO,aACR,QAAQ,SACX,KAAK,KACX,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAc1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,SAAS,aACV,QAAQ,2BAEd,aAAa,CAAC,MAAM,CAAC,WACjB,MAAM,WACN,UAAU,KACjB,aAAa,CAAC,WAAW,CAuBxB,CAAC;AAEL,qFAAqF;AACrF,eAAO,MAAM,OAAO,aACR,QAAQ,qBAEjB,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAUtC,CAAC"}
@@ -0,0 +1,87 @@
1
+ import { Schema } from 'effect';
2
+ import { dotted } from './node.js';
3
+ import { pick } from './values.js';
4
+ /*
5
+ * A Route's places: those on its path, each with its key, what its Loader
6
+ * is handed, its Render Mode and its data; and every place of the tree as
7
+ * Schemas, with the Stale time each is kept fresh for.
8
+ */
9
+ /** The places on a Route's path, from the root down. The not-found Route has none. */
10
+ export const placesOn = (children, route, staleTimes) => {
11
+ const out = [];
12
+ let layer = children;
13
+ let value = route;
14
+ const at = [];
15
+ let params = {};
16
+ let render = 'static';
17
+ while (value) {
18
+ const node = layer[value._tag];
19
+ if (!node)
20
+ break;
21
+ at.push(value._tag);
22
+ params = { ...params, ...pick(node.params, value) };
23
+ render = node.render ?? render;
24
+ const name = dotted(at);
25
+ out.push({
26
+ name,
27
+ key: JSON.stringify([name, params]),
28
+ params: { ...params, ...pick(node.query, value) },
29
+ render,
30
+ staleTime: staleTimes.get(name) ?? 0,
31
+ input: node.input,
32
+ });
33
+ layer = node.children;
34
+ value = value.page;
35
+ }
36
+ return out;
37
+ };
38
+ /** The nodes on a Route's path, from the root down, each with its dotted name. */
39
+ export const nodesOn = (children, route) => {
40
+ const nodes = [];
41
+ let layer = children;
42
+ let value = route;
43
+ const at = [];
44
+ while (value) {
45
+ const node = layer[value._tag];
46
+ if (!node)
47
+ break;
48
+ at.push(value._tag);
49
+ nodes.push([dotted(at), node]);
50
+ layer = node.children;
51
+ value = value.page;
52
+ }
53
+ return nodes;
54
+ };
55
+ /**
56
+ * Every place of the tree, as Schemas, from the root down. A place's Stale
57
+ * time is its own, else its parent's, else `staleTime`; a static place's is
58
+ * `Infinity`, and one that says its own throws.
59
+ */
60
+ export const allPlaces = (children, staleTime = 0, at = [], params = {}, render = 'static') => Object.entries(children).flatMap(([tag, node]) => {
61
+ const here = [...at, tag];
62
+ const name = dotted(here);
63
+ const fields = { ...params, ...node.params };
64
+ const mode = node.render ?? render;
65
+ if (mode === 'static' && node.staleTime !== undefined)
66
+ throw new Error(`[@kestack/kabuki/routing] ${name} is static: its data is fresh until the next deploy, so it has no staleTime`);
67
+ const stale = node.staleTime ?? staleTime;
68
+ return [
69
+ {
70
+ name,
71
+ params: Schema.Struct({ ...fields, ...node.query }),
72
+ render: mode,
73
+ staleTime: mode === 'static' ? Infinity : stale,
74
+ input: node.input,
75
+ },
76
+ ...allPlaces(node.children, stale, here, fields, mode),
77
+ ];
78
+ });
79
+ /** Every path of the tree, as written from the root: `/projects/:id/tasks/:task`. */
80
+ export const pathsOf = (children, above = '') => Object.entries(children).flatMap(([tag, node]) => {
81
+ const own = node.path.split('/').filter(Boolean).join('/');
82
+ const path = own ? `${above}/${own}` : above;
83
+ return [
84
+ [tag, path || '/'],
85
+ ...pathsOf(node.children, path).map(([name, written]) => [`${tag}.${name}`, written]),
86
+ ];
87
+ });
@@ -0,0 +1,53 @@
1
+ import type { Exactly, Loaders, LoadersOf } from './loader.ts';
2
+ import type { Metadata } from './metadata.ts';
3
+ import type { Codec, LoaderNames, NameOf, NotFound, Place, PlaceData, PlaceSchema, PlacesOf, Read, Redirects, RouteOf, StaticNames, Tree } from './node.ts';
4
+ export type RoutesOptions<C, D> = {
5
+ readonly redirect?: Redirects<C, D>;
6
+ /** The root's Metadata, under every place's: the site's name, its default description. */
7
+ readonly metadata?: Metadata;
8
+ /** The not-found Route's Metadata, over the root's. */
9
+ readonly notFound?: Metadata;
10
+ /** The Stale time of every dynamic or client place that says none, nor its parent: 0 unless said. */
11
+ readonly staleTime?: number;
12
+ };
13
+ /** What `routesOf` gives besides a constructor per place. */
14
+ export interface RoutesApi<C> {
15
+ /** The Schema of every Route. */
16
+ readonly route: Codec<RouteOf<C>>;
17
+ /** The Schema of every place's dotted name: `Blog.Post`. */
18
+ readonly place: Codec<NameOf<C>>;
19
+ /** The not-found Route, for a path that names no place. */
20
+ readonly NotFound: (args: {
21
+ readonly path: string;
22
+ }) => NotFound;
23
+ /** A path and query, like `/projects/4?tab=files`, read as a Route. */
24
+ readonly read: (url: string) => Read<RouteOf<C>>;
25
+ /** A Route written as its path and query, without any base. */
26
+ readonly path: (route: RouteOf<C>) => string;
27
+ /** Every place's path, as written from the root, by dotted name. */
28
+ readonly paths: () => Readonly<Record<string, string>>;
29
+ /** The Metadata of a Route, or of a URL, from the data of its places: pure, so a server can call it. */
30
+ readonly metadata: (of: RouteOf<C> | string, data?: PlaceData) => Metadata;
31
+ /** The places on a Route's path, from the root down. */
32
+ readonly places: (of: RouteOf<C> | string) => ReadonlyArray<Place<NameOf<C>>>;
33
+ /** Every place of the tree, as Schemas, from the root down. */
34
+ readonly every: ReadonlyArray<PlaceSchema<NameOf<C>>>;
35
+ /** Every place with data, by dotted name, with its data's Schema. */
36
+ readonly data: ReadonlyArray<readonly [string, Codec<unknown>]>;
37
+ /**
38
+ * The Loaders of every place with data, by dotted name, checked by type:
39
+ * one for each, and no other. A static place's is given its params and
40
+ * query; a dynamic or client place's, the request too.
41
+ */
42
+ readonly loaders: <const L extends Partial<LoadersOf<PlacesOf<C>, RouteOf<C>>>>(loaders: Exactly<L, LoaderNames<C>> & Partial<LoadersOf<PlacesOf<C>, RouteOf<C>>>) => Loaders<L, StaticNames<C>>;
43
+ /** The nodes as written. */
44
+ readonly children: C;
45
+ }
46
+ /**
47
+ * Every place of an app, from the nodes under the root. `redirect` names
48
+ * paths that are never a place, each with the Route it is replaced by,
49
+ * from the params its path names:
50
+ * `{ '/posts/:slug': (r, { slug }) => r.Blog.Post({ slug }) }`.
51
+ */
52
+ export declare const routesOf: <C extends object, D>(children: C, options?: RoutesOptions<C, D>) => Tree<C, RouteOf<C>, {}> & RoutesApi<C>;
53
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/routing/route/route.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,KAAK,EAGV,KAAK,EACL,WAAW,EACX,MAAM,EACN,QAAQ,EACR,KAAK,EACL,SAAS,EACT,WAAW,EACX,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,OAAO,EACP,WAAW,EACX,IAAI,EAEL,MAAM,WAAW,CAAC;AAwEnB,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,IAAI;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpC,0FAA0F;IAC1F,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B,qGAAqG;IACrG,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC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,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAChE;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,CAChB,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAE3D,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAC1C,OAAO,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,4BAA4B;IAC5B,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;CACtB;AAED;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,YAChC,CAAC,YACF,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,KAC3B,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CA0EvC,CAAC"}
@@ -0,0 +1,148 @@
1
+ import { Schema } from 'effect';
2
+ import { merge } from './metadata.js';
3
+ import { dotted } from './node.js';
4
+ import { allPlaces, pathsOf, placesOn } from './places.js';
5
+ import { decodeSegment, fit, match, write } from './url.js';
6
+ import { dataSchemas, levelSchema, pick } from './values.js';
7
+ /*
8
+ * The Routes, worked out from the pages under the root: a Schema for every
9
+ * level, a constructor for every place, both directions between a URL and
10
+ * a Route, each place's data, Render Mode and Metadata, and the type of
11
+ * every Loader. It holds no state and runs nothing.
12
+ *
13
+ * A Route value is one tagged object per level, the one below under `page`
14
+ * when the URL goes on:
15
+ *
16
+ * router.Settings.Billing() → { _tag: 'Settings', page: { _tag: 'Billing' } }
17
+ * router.Settings() → { _tag: 'Settings' }
18
+ *
19
+ * A place is named by its tags from the root, dotted: `Settings.Billing`.
20
+ * This file makes the Routes from their parts: `node.ts` the types,
21
+ * `values.ts` each level's Schemas, `places.ts` the places, `url.ts` a URL
22
+ * both ways, and `metadata.ts` the Metadata.
23
+ */
24
+ /**
25
+ * The Metadata of a value: the deepest node that says anything wins, field
26
+ * by field. A node whose Metadata is a function is handed its data, or
27
+ * `undefined` until it is there.
28
+ */
29
+ const metadataOf = (children, value, data, at = []) => {
30
+ if (!value)
31
+ return {};
32
+ const node = children[value._tag];
33
+ if (!node)
34
+ return {};
35
+ const here = [...at, value._tag];
36
+ const own = typeof node.metadata === 'function'
37
+ ? node.metadata({ ...pick(node.params, value), ...pick(node.query, value) }, data[dotted(here)])
38
+ : (node.metadata ?? {});
39
+ const below = metadataOf(node.children, value.page, data, here);
40
+ return merge(own, below);
41
+ };
42
+ /** Throws, naming both, if two places are written at the same path and neither holds the other. */
43
+ const checkPaths = (children) => {
44
+ const seen = new Map();
45
+ for (const [name, path] of pathsOf(children)) {
46
+ const shape = path.replace(/:[^/]+/g, ':');
47
+ const before = seen.get(shape);
48
+ if (before !== undefined &&
49
+ !name.startsWith(`${before}.`) &&
50
+ !before.startsWith(`${name}.`))
51
+ throw new Error(`[@kestack/kabuki/routing] ${before} and ${name} are both at ${path}: a URL must name one place`);
52
+ if (before === undefined)
53
+ seen.set(shape, name);
54
+ }
55
+ };
56
+ /**
57
+ * Every place of an app, from the nodes under the root. `redirect` names
58
+ * paths that are never a place, each with the Route it is replaced by,
59
+ * from the params its path names:
60
+ * `{ '/posts/:slug': (r, { slug }) => r.Blog.Post({ slug }) }`.
61
+ */
62
+ export const routesOf = (children, options = {}) => {
63
+ const nodes = children;
64
+ checkPaths(nodes);
65
+ const ctors = constructors(nodes);
66
+ const redirects = Object.entries((options.redirect ?? {})).map(([from, to]) => ({ template: from.split('/').filter(Boolean), to }));
67
+ const read = (url) => {
68
+ const { pathname, search } = new URL(url, 'http://route');
69
+ const parts = pathname.split('/').filter(Boolean).map(decodeSegment);
70
+ const notFound = { _tag: 'NotFound', path: pathname };
71
+ if (parts.some((part) => part === undefined))
72
+ return { _tag: 'At', route: notFound };
73
+ const rest = parts;
74
+ for (const { template, to } of redirects) {
75
+ if (template.length !== rest.length)
76
+ continue;
77
+ const params = fit(template, rest);
78
+ if (params)
79
+ return { _tag: 'Redirect', route: to(ctors, params) };
80
+ }
81
+ const found = match(nodes, rest, new URLSearchParams(search));
82
+ return { _tag: 'At', route: found ?? notFound };
83
+ };
84
+ const pathOf = (route) => {
85
+ const value = route;
86
+ if (value._tag === 'NotFound')
87
+ return String(value.path);
88
+ const out = { segments: [], query: new URLSearchParams() };
89
+ write(nodes, value, out);
90
+ const query = out.query.toString();
91
+ return `/${out.segments.join('/')}${query ? `?${query}` : ''}`;
92
+ };
93
+ const routeOf = (of) => (typeof of === 'string' ? read(of).route : of);
94
+ const every = allPlaces(nodes, options.staleTime);
95
+ const names = every.map((place) => place.name);
96
+ const staleTimes = new Map(every.map((place) => [place.name, place.staleTime]));
97
+ const api = {
98
+ route: levelSchema(nodes, true),
99
+ place: (names.length > 0
100
+ ? Schema.Literals(names)
101
+ : Schema.Never),
102
+ NotFound: ({ path }) => ({ _tag: 'NotFound', path }),
103
+ read,
104
+ path: pathOf,
105
+ paths: () => Object.fromEntries(pathsOf(nodes)),
106
+ metadata: (of, data = {}) => {
107
+ const value = routeOf(of);
108
+ return merge(options.metadata ?? {}, value._tag === 'NotFound'
109
+ ? (options.notFound ?? {})
110
+ : metadataOf(nodes, value, data));
111
+ },
112
+ places: (of) => {
113
+ const value = routeOf(of);
114
+ return (value._tag === 'NotFound' ? [] : placesOn(nodes, value, staleTimes));
115
+ },
116
+ every: every,
117
+ data: dataSchemas(nodes),
118
+ // Typed by `RoutesApi`.
119
+ loaders: ((loaders) => loaders),
120
+ children,
121
+ };
122
+ return Object.assign(ctors, api);
123
+ };
124
+ /**
125
+ * A constructor per node, whose value is a whole Route: each nested call
126
+ * wraps its value in its ancestors'. A node with children is a function
127
+ * too, for the URL that ends at it.
128
+ */
129
+ const constructors = (children) => {
130
+ const build = (layer, at, wrap) => Object.fromEntries(Object.entries(layer).map(([tag, node]) => {
131
+ const here = [...at, tag];
132
+ const own = (args) => ({
133
+ _tag: tag,
134
+ ...pick(node.params, args),
135
+ ...pick(node.query, args),
136
+ });
137
+ const make = (args = {}) => wrap(own(args), args);
138
+ return [
139
+ tag,
140
+ Object.assign(make, {
141
+ at: here,
142
+ ...(node.input ? { data: node.input } : {}),
143
+ ...build(node.children, here, (value, args) => wrap({ ...own(args), page: value }, args)),
144
+ }),
145
+ ];
146
+ }));
147
+ return build(children, [], (value) => value);
148
+ };
@@ -0,0 +1,13 @@
1
+ import type { Children, Value } from './node.ts';
2
+ /** One segment, decoded; a malformed one names no place. */
3
+ export declare const decodeSegment: (segment: string) => string | undefined;
4
+ /** The raw params a template's segments name, if the segments fit it exactly. */
5
+ export declare const fit: (template: ReadonlyArray<string>, rest: ReadonlyArray<string>) => Record<string, string> | undefined;
6
+ /** The value a URL's segments name under one layer, if any. */
7
+ export declare const match: (children: Children, rest: ReadonlyArray<string>, search: URLSearchParams) => Value | undefined;
8
+ /** A value's segments and query under one layer. */
9
+ export declare const write: (children: Children, value: Value, out: {
10
+ segments: Array<string>;
11
+ query: URLSearchParams;
12
+ }) => void;
13
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../../src/routing/route/url.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAiB,KAAK,EAAE,MAAM,WAAW,CAAC;AAyBhE,4DAA4D;AAC5D,eAAO,MAAM,aAAa,YAAa,MAAM,KAAG,MAAM,GAAG,SAMxD,CAAC;AAEF,iFAAiF;AACjF,eAAO,MAAM,GAAG,aACJ,aAAa,CAAC,MAAM,CAAC,QACzB,aAAa,CAAC,MAAM,CAAC,KAC1B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAQ3B,CAAC;AAEF,+DAA+D;AAC/D,eAAO,MAAM,KAAK,aACN,QAAQ,QACZ,aAAa,CAAC,MAAM,CAAC,UACnB,eAAe,KACtB,KAAK,GAAG,SA2BV,CAAC;AAEF,oDAAoD;AACpD,eAAO,MAAM,KAAK,aACN,QAAQ,SACX,KAAK,OACP;IAAE,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,SAczD,CAAC"}
@@ -0,0 +1,79 @@
1
+ import { Schema } from 'effect';
2
+ import { hasChildren, segments } from './node.js';
3
+ /*
4
+ * A URL read as a value and a value written as a URL, layer by layer:
5
+ * path segments by each node's template and params Schema, the query by
6
+ * its query Schema.
7
+ */
8
+ const structOf = (fields) => Schema.Struct(fields);
9
+ const decode = (fields, raw) => {
10
+ const exit = Schema.decodeUnknownExit(structOf(fields))(raw);
11
+ return exit._tag === 'Success' ? exit.value : undefined;
12
+ };
13
+ const encode = (fields, value) => Schema.encodeUnknownSync(structOf(fields))(Object.fromEntries(Object.keys(fields)
14
+ .filter((key) => value[key] !== undefined)
15
+ .map((key) => [key, value[key]])));
16
+ /** One segment, decoded; a malformed one names no place. */
17
+ export const decodeSegment = (segment) => {
18
+ try {
19
+ return decodeURIComponent(segment);
20
+ }
21
+ catch {
22
+ return undefined;
23
+ }
24
+ };
25
+ /** The raw params a template's segments name, if the segments fit it exactly. */
26
+ export const fit = (template, rest) => {
27
+ const raw = {};
28
+ const fits = template.every((part, at) => {
29
+ if (!part.startsWith(':'))
30
+ return part === rest[at];
31
+ raw[part.slice(1)] = rest[at];
32
+ return true;
33
+ });
34
+ return fits ? raw : undefined;
35
+ };
36
+ /** The value a URL's segments name under one layer, if any. */
37
+ export const match = (children, rest, search) => {
38
+ for (const [tag, node] of Object.entries(children)) {
39
+ const template = segments(node.path);
40
+ if (template.length > rest.length)
41
+ continue;
42
+ const raw = fit(template, rest);
43
+ if (!raw)
44
+ continue;
45
+ const params = decode(node.params, raw);
46
+ const query = decode(node.query, Object.fromEntries(Object.keys(node.query).flatMap((key) => {
47
+ const found = search.get(key);
48
+ return found === null ? [] : [[key, found]];
49
+ })));
50
+ if (!params || !query)
51
+ continue;
52
+ const own = { _tag: tag, ...params, ...query };
53
+ const below = rest.slice(template.length);
54
+ const page = hasChildren(node)
55
+ ? match(node.children, below, search)
56
+ : undefined;
57
+ if (page)
58
+ return { ...own, page };
59
+ // A page with pages is a place on its own too, when the URL ends at it.
60
+ if (below.length === 0)
61
+ return own;
62
+ }
63
+ return undefined;
64
+ };
65
+ /** A value's segments and query under one layer. */
66
+ export const write = (children, value, out) => {
67
+ const node = children[value._tag];
68
+ if (!node)
69
+ return;
70
+ const params = encode(node.params, value);
71
+ for (const part of segments(node.path))
72
+ out.segments.push(part.startsWith(':')
73
+ ? encodeURIComponent(String(params[part.slice(1)]))
74
+ : part);
75
+ for (const [key, found] of Object.entries(encode(node.query, value)))
76
+ out.query.set(key, String(found));
77
+ if (value.page)
78
+ write(node.children, value.page, out);
79
+ };
@@ -0,0 +1,12 @@
1
+ import type { AnyNode, Children, Codec, Fields, Value } from './node.ts';
2
+ /** The Schema of one level: a case per child, and at the root the not-found Route. */
3
+ export declare const levelSchema: (children: Children, root: boolean) => Codec<unknown>;
4
+ /** Every place with data, by dotted name, with its data's Schema. */
5
+ export declare const dataSchemas: (children: Children, at?: ReadonlyArray<string>) => ReadonlyArray<readonly [string, Codec<unknown>]>;
6
+ /** The fields of a value that `fields` names. */
7
+ export declare const pick: (fields: Fields, value: Value | undefined) => Record<string, unknown>;
8
+ /** The params of a node's value, as one string: two values with the same params are the same place. */
9
+ export declare const paramsKey: (node: AnyNode, value: Value) => string;
10
+ /** The value one level down a path of tags, if the Route goes that way. */
11
+ export declare const valueAt: (route: Value | null | undefined, at: ReadonlyArray<string>) => Value | undefined;
12
+ //# sourceMappingURL=values.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../../../src/routing/route/values.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAiBzE,sFAAsF;AACtF,eAAO,MAAM,WAAW,aACZ,QAAQ,QACZ,OAAO,KACZ,KAAK,CAAC,OAAO,CAUf,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,WAAW,aACZ,QAAQ,OACd,aAAa,CAAC,MAAM,CAAC,KACxB,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAM9C,CAAC;AAEL,iDAAiD;AACjD,eAAO,MAAM,IAAI,WACP,MAAM,SACP,KAAK,GAAG,SAAS,KACvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAKtB,CAAC;AAEJ,uGAAuG;AACvG,eAAO,MAAM,SAAS,SAAU,OAAO,SAAS,KAAK,KAAG,MACW,CAAC;AAEpE,2EAA2E;AAC3E,eAAO,MAAM,OAAO,UACX,KAAK,GAAG,IAAI,GAAG,SAAS,MAC3B,aAAa,CAAC,MAAM,CAAC,KACxB,KAAK,GAAG,SAKV,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { Schema } from 'effect';
2
+ import { dotted } from './node.js';
3
+ /*
4
+ * A Route's values: the Schema of each level, the key of a node's params,
5
+ * the own params and query of a value, and every place's data Schema.
6
+ */
7
+ /** The Schema of the fields a node's value holds besides its tag. */
8
+ const fieldsOf = (node) => ({
9
+ ...node.params,
10
+ ...node.query,
11
+ ...(Object.keys(node.children).length > 0
12
+ ? { page: Schema.optionalKey(levelSchema(node.children, false)) }
13
+ : {}),
14
+ });
15
+ const cache = new WeakMap();
16
+ /** The Schema of one level: a case per child, and at the root the not-found Route. */
17
+ export const levelSchema = (children, root) => {
18
+ if (!root && cache.has(children))
19
+ return cache.get(children);
20
+ const schema = Schema.TaggedUnion({
21
+ ...Object.fromEntries(Object.entries(children).map(([tag, node]) => [tag, fieldsOf(node)])),
22
+ ...(root ? { NotFound: { path: Schema.String } } : {}),
23
+ });
24
+ if (!root)
25
+ cache.set(children, schema);
26
+ return schema;
27
+ };
28
+ /** Every place with data, by dotted name, with its data's Schema. */
29
+ export const dataSchemas = (children, at = []) => Object.entries(children).flatMap(([tag, node]) => [
30
+ ...(node.input
31
+ ? [[dotted([...at, tag]), node.input]]
32
+ : []),
33
+ ...dataSchemas(node.children, [...at, tag]),
34
+ ]);
35
+ /** The fields of a value that `fields` names. */
36
+ export const pick = (fields, value) => Object.fromEntries(Object.keys(fields)
37
+ .filter((key) => value?.[key] !== undefined)
38
+ .map((key) => [key, value[key]]));
39
+ /** The params of a node's value, as one string: two values with the same params are the same place. */
40
+ export const paramsKey = (node, value) => JSON.stringify(Object.keys(node.params).map((key) => value[key]));
41
+ /** The value one level down a path of tags, if the Route goes that way. */
42
+ export const valueAt = (route, at) => {
43
+ let value = route ?? undefined;
44
+ for (const tag of at)
45
+ value = value?._tag === tag ? value.page : undefined;
46
+ return value;
47
+ };
@@ -0,0 +1,123 @@
1
+ import type { AnchorHTMLAttributes, ButtonHTMLAttributes, ReactNode } from 'react';
2
+ import type { AnyRoute, MoveOptions } from '../capability/index.ts';
3
+ import type { Preload } from './define.ts';
4
+ import type { How, Metadata } from '../route/index.ts';
5
+ /** One entry of the router's history: its key and its Route. */
6
+ export interface Entry<Route extends AnyRoute = AnyRoute> {
7
+ readonly key: string;
8
+ readonly route: Route;
9
+ /** The element on the page it goes to, after its `#`. */
10
+ readonly hash?: string;
11
+ }
12
+ /** A move the Router holds while it loads the data of its places: where to, and how. */
13
+ export interface Pending<Route extends AnyRoute = AnyRoute> {
14
+ readonly to: Route;
15
+ readonly how: 'push' | 'replace' | 'load' | 'back' | 'forward';
16
+ }
17
+ /** What the router's View hands everything drawn below it: drawing data, read from the Snapshot shown, and its Sends. */
18
+ export interface Drawing {
19
+ readonly href: (route: AnyRoute) => string;
20
+ readonly entries: ReadonlyArray<Entry>;
21
+ readonly at: number;
22
+ readonly move: {
23
+ readonly from: AnyRoute | null;
24
+ readonly to: AnyRoute;
25
+ readonly how: How;
26
+ /** `false`: the push or replace said to leave every scroll as it is. */
27
+ readonly resetScroll?: boolean;
28
+ /** How the push or replace said its hash's element is scrolled into view. */
29
+ readonly hashScrollIntoView?: MoveOptions['hashScrollIntoView'];
30
+ };
31
+ readonly pending: Pending | null;
32
+ /** The Metadata the Routes give the current entry, from its params alone. */
33
+ readonly metadata: Metadata;
34
+ readonly go: (by: number) => void;
35
+ readonly reload: () => void;
36
+ readonly preload: (route: AnyRoute) => void;
37
+ /** When a link preloads, unless it says. */
38
+ readonly linkPreload: {
39
+ readonly mode: Preload;
40
+ readonly delay: number;
41
+ };
42
+ }
43
+ export declare const RouterContext: import("react").Context<Drawing | undefined>;
44
+ /** What a link clicked says besides where it goes: its hash, and what its `Router.Link` said of scroll. */
45
+ export declare const linkOptions: (link: Element, url: URL) => MoveOptions;
46
+ export declare const useDrawing: (what: string) => Drawing;
47
+ /**
48
+ * Writes the Metadata to the document after every move, and when a page's
49
+ * data comes: the title, and every tag marked `data-kabuki`, which replace
50
+ * the ones marked before. Tags nobody marked are left alone, and an app
51
+ * routing in memory never touches the document.
52
+ */
53
+ export declare function MetadataWriter({ metadata }: {
54
+ readonly metadata: Metadata;
55
+ }): null;
56
+ export type LinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & {
57
+ /** Where it goes: a Route, never a string. */
58
+ readonly to: AnyRoute;
59
+ /**
60
+ * When it preloads its Route's data and code: on hover or focus, after
61
+ * `preloadDelay`; once it scrolls into view; or never. The Routes' default
62
+ * unless said, `'intent'` unless they say.
63
+ */
64
+ readonly preload?: Preload;
65
+ /** How long, in milliseconds, an `'intent'` link waits before it preloads. */
66
+ readonly preloadDelay?: number;
67
+ /** `false`: its move leaves every scroll as it is, as opening a post below its list. */
68
+ readonly resetScroll?: boolean;
69
+ /** The element on the page it goes to, by id: `href` ends `#hash`. */
70
+ readonly hash?: string;
71
+ /** How that element is scrolled into view; `false` leaves it. */
72
+ readonly hashScrollIntoView?: MoveOptions['hashScrollIntoView'];
73
+ readonly children?: ReactNode;
74
+ };
75
+ /**
76
+ * A link to a Route. It draws a plain `<a href>`, so a new tab, a copied
77
+ * link and a crawler all see the real URL; the router catches a plain click.
78
+ * It asks the Router to preload where it goes, as `preload` says: each ask
79
+ * is one Message, so the Timeline shows it.
80
+ */
81
+ export declare function Link({ to, preload, preloadDelay, resetScroll, hash, hashScrollIntoView, onMouseEnter, onMouseLeave, onFocus, onBlur, onTouchStart, ...rest }: LinkProps): import("react").JSX.Element;
82
+ /** What a component drawn inside the app can read of the router, and its own Back, Forward and reload. */
83
+ export interface RouterState<Route extends AnyRoute = AnyRoute> {
84
+ readonly route: Route;
85
+ readonly href: string;
86
+ readonly entries: ReadonlyArray<Entry<Route>>;
87
+ readonly at: number;
88
+ readonly move: {
89
+ readonly from: Route | null;
90
+ readonly to: Route;
91
+ readonly how: How;
92
+ readonly resetScroll?: boolean;
93
+ readonly hashScrollIntoView?: MoveOptions['hashScrollIntoView'];
94
+ };
95
+ /** The move the Router holds while it loads, if any. */
96
+ readonly pending: Pending<Route> | null;
97
+ readonly metadata: Metadata;
98
+ readonly title: string | undefined;
99
+ readonly canGoBack: boolean;
100
+ readonly canGoForward: boolean;
101
+ readonly back: () => void;
102
+ readonly forward: () => void;
103
+ /** Move to entry `at` of the history. */
104
+ readonly goTo: (at: number) => void;
105
+ /** Load every page on screen again, its data shown meanwhile: a failed page retries. */
106
+ readonly reload: () => void;
107
+ /** Warm the Data cache for a Route. */
108
+ readonly preload: (route: Route) => void;
109
+ }
110
+ /**
111
+ * The router, for a component drawn inside a `Router.app`: an address bar, a
112
+ * history list, a retry button. Name the app's Route,
113
+ * `useRouter<Route>()` with `type Route = typeof router.route.Type`, to read
114
+ * its Routes as that type: every Route the Router holds is one of them.
115
+ */
116
+ export declare const useRouter: <Route extends AnyRoute = AnyRoute>() => RouterState<Route>;
117
+ /**
118
+ * A button that loads every page on screen again: for a failed page's
119
+ * screen, so the page whose Loader broke retries. Any other button props
120
+ * pass through.
121
+ */
122
+ export declare function Retry({ onClick, type, ...rest }: ButtonHTMLAttributes<HTMLButtonElement>): import("react").JSX.Element;
123
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/routing/router/context.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EAGpB,SAAS,EAEV,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEvD,gEAAgE;AAChE,MAAM,WAAW,KAAK,CAAC,KAAK,SAAS,QAAQ,GAAG,QAAQ;IACtD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,yDAAyD;IACzD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wFAAwF;AACxF,MAAM,WAAW,OAAO,CAAC,KAAK,SAAS,QAAQ,GAAG,QAAQ;IACxD,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAChE;AAED,yHAAyH;AACzH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,MAAM,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,EAAE,MA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