@kasperrt/smolter 0.4.2 → 0.4.4
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/.generated/client/hash-history.ts +27 -0
- package/.generated/client/hydration.ts +98 -0
- package/.generated/client/root-data.ts +52 -0
- package/.generated/core/environment.ts +1 -0
- package/.generated/core/navigation.ts +1 -0
- package/.generated/core/prepare-routes.ts +50 -0
- package/.generated/core/presentation.ts +1 -1
- package/.generated/core/responses.ts +12 -0
- package/.generated/core/utils.ts +5 -2
- package/.generated/preact/await.tsx +1 -0
- package/.generated/preact/client.tsx +8 -27
- package/.generated/preact/deferred-hydration.ts +1 -98
- package/.generated/preact/document.tsx +10 -0
- package/.generated/preact/index.ts +11 -2
- package/.generated/preact/lazy-route.ts +7 -0
- package/.generated/preact/navigation.tsx +19 -5
- package/.generated/preact/root-data.ts +1 -45
- package/.generated/preact/route-hooks.tsx +12 -2
- package/.generated/preact/route-types.ts +14 -0
- package/.generated/preact/router.tsx +5 -48
- package/.generated/react/client.tsx +130 -0
- package/.generated/react/document.tsx +235 -0
- package/.generated/react/fetcher.ts +29 -7
- package/.generated/react/hooks.ts +20 -18
- package/.generated/react/index.ts +28 -2
- package/.generated/react/lazy-route.ts +116 -0
- package/.generated/react/link.ts +1 -38
- package/.generated/react/navigation-state.ts +13 -0
- package/.generated/react/navigation.ts +145 -0
- package/.generated/react/outlet.ts +48 -0
- package/.generated/react/root-context.ts +22 -0
- package/.generated/react/route-hooks.ts +159 -0
- package/.generated/react/route-types.ts +91 -0
- package/.generated/react/router.ts +50 -0
- package/.generated/react/runtime.ts +1 -0
- package/.generated/server/application.tsx +18 -250
- package/.generated/server/assets.ts +7 -0
- package/.generated/server/dispatch.ts +87 -0
- package/.generated/server/handler.ts +3 -0
- package/.generated/server/http.ts +2 -0
- package/.generated/server/index.ts +2 -0
- package/.generated/server/node.ts +5 -2
- package/.generated/server/preact.ts +5 -2
- package/.generated/server/react.ts +34 -0
- package/.generated/server/render-application.ts +203 -0
- package/.generated/vite/application/lazy-files.ts +2 -1
- package/.generated/vite/application/vite.ts +12 -4
- package/.generated/vite/react.ts +11 -0
- package/CHANGELOG.md +20 -0
- package/README.md +48 -48
- package/dist/client/hash-history.d.ts +2 -0
- package/dist/client/hash-history.js +26 -0
- package/dist/client/hydration.d.ts +10 -0
- package/dist/{preact/deferred-hydration.js → client/hydration.js} +1 -1
- package/dist/client/root-data.d.ts +14 -0
- package/dist/{preact → client}/root-data.js +1 -1
- package/dist/core/environment.d.ts +1 -0
- package/dist/core/navigation.d.ts +1 -0
- package/dist/core/prepare-routes.d.ts +7 -0
- package/dist/core/prepare-routes.js +28 -0
- package/dist/core/presentation.js +1 -1
- package/dist/core/responses.d.ts +12 -0
- package/dist/core/responses.js +5 -0
- package/dist/core/utils.d.ts +5 -2
- package/dist/core/utils.js +1 -2
- package/dist/preact/await.d.ts +1 -0
- package/dist/preact/await.js +1 -0
- package/dist/preact/client.d.ts +7 -1
- package/dist/preact/client.js +11 -27
- package/dist/preact/deferred-hydration.d.ts +1 -10
- package/dist/preact/document.d.ts +10 -0
- package/dist/preact/document.js +11 -2
- package/dist/preact/index.d.ts +6 -2
- package/dist/preact/index.js +1 -1
- package/dist/preact/lazy-route.d.ts +2 -0
- package/dist/preact/lazy-route.js +6 -0
- package/dist/preact/navigation-state.js +1 -1
- package/dist/preact/navigation.d.ts +6 -0
- package/dist/preact/navigation.js +9 -5
- package/dist/preact/root-data.d.ts +1 -8
- package/dist/preact/route-hooks.d.ts +10 -0
- package/dist/preact/route-hooks.js +13 -3
- package/dist/preact/route-types.d.ts +14 -0
- package/dist/preact/router.d.ts +5 -2
- package/dist/preact/router.js +4 -26
- package/dist/react/client.d.ts +20 -0
- package/dist/react/client.js +86 -0
- package/dist/react/document.d.ts +25 -0
- package/dist/react/document.js +169 -0
- package/dist/react/fetcher.d.ts +8 -4
- package/dist/react/fetcher.js +12 -1
- package/dist/react/form.js +1 -1
- package/dist/react/hooks.d.ts +7 -6
- package/dist/react/index.d.ts +13 -2
- package/dist/react/index.js +7 -2
- package/dist/react/lazy-route.d.ts +22 -0
- package/dist/react/lazy-route.js +57 -0
- package/dist/react/link.d.ts +1 -12
- package/dist/react/navigation-state.d.ts +2 -0
- package/dist/react/navigation-state.js +9 -0
- package/dist/react/navigation.d.ts +33 -0
- package/dist/react/navigation.js +64 -0
- package/dist/react/outlet.d.ts +16 -0
- package/dist/react/outlet.js +26 -0
- package/dist/react/root-context.d.ts +14 -0
- package/dist/react/root-context.js +10 -0
- package/dist/react/route-hooks.d.ts +34 -0
- package/dist/react/route-hooks.js +89 -0
- package/dist/react/route-types.d.ts +69 -0
- package/dist/react/router.d.ts +10 -0
- package/dist/react/router.js +22 -0
- package/dist/react/runtime.d.ts +1 -1
- package/dist/react/runtime.js +1 -1
- package/dist/server/application.d.ts +4 -5
- package/dist/server/application.js +9 -154
- package/dist/server/assets.d.ts +2 -0
- package/dist/server/assets.js +6 -0
- package/dist/server/dispatch.d.ts +5 -0
- package/dist/server/dispatch.js +50 -0
- package/dist/server/handler.d.ts +3 -0
- package/dist/server/http.d.ts +2 -0
- package/dist/server/http.js +2 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +2 -1
- package/dist/server/node.d.ts +5 -1
- package/dist/server/preact.d.ts +5 -1
- package/dist/server/preact.js +2 -1
- package/dist/server/react.d.ts +10 -0
- package/dist/server/react.js +22 -0
- package/dist/server/render-application.d.ts +31 -0
- package/dist/server/render-application.js +118 -0
- package/dist/vite/application/lazy-files.d.ts +1 -1
- package/dist/vite/application/lazy-files.js +2 -2
- package/dist/vite/application/vite.d.ts +2 -1
- package/dist/vite/application/vite.js +12 -5
- package/dist/vite/react.d.ts +4 -0
- package/dist/vite/react.js +9 -1
- package/jsr.json +10 -6
- package/package.json +21 -12
- package/.generated/core/resource-types.ts +0 -44
- package/.generated/core/resources.ts +0 -444
- package/.generated/react/data.ts +0 -25
- package/.generated/react/resources/components.tsx +0 -404
- package/dist/core/resource-types.d.ts +0 -37
- package/dist/core/resources.d.ts +0 -19
- package/dist/core/resources.js +0 -345
- package/dist/react/data.d.ts +0 -5
- package/dist/react/data.js +0 -3
- package/dist/react/link.js +0 -27
- package/dist/react/resources/components.d.ts +0 -64
- package/dist/react/resources/components.js +0 -239
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource react */
|
|
2
|
-
import type {
|
|
3
|
-
DataResult,
|
|
4
|
-
NavigationState,
|
|
5
|
-
Params,
|
|
6
|
-
ResourceModule,
|
|
7
|
-
RouteState,
|
|
8
|
-
} from "../../core/resource-types.ts";
|
|
9
|
-
import type { ResourceRouter } from "../../core/resources.ts";
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
Component,
|
|
13
|
-
type ComponentType,
|
|
14
|
-
createContext,
|
|
15
|
-
type PropsWithChildren,
|
|
16
|
-
type ReactNode,
|
|
17
|
-
useCallback,
|
|
18
|
-
useContext,
|
|
19
|
-
useEffect,
|
|
20
|
-
useMemo,
|
|
21
|
-
useRef,
|
|
22
|
-
useState,
|
|
23
|
-
useSyncExternalStore,
|
|
24
|
-
} from "react";
|
|
25
|
-
|
|
26
|
-
export interface ResourceRouteModule extends ResourceModule {
|
|
27
|
-
default?: ComponentType;
|
|
28
|
-
ErrorBoundary?: ComponentType<{ retry: () => void }>;
|
|
29
|
-
HydrateFallback?: ComponentType;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const RouterContext = createContext<ResourceRouter | null>(null);
|
|
33
|
-
const RouteContext = createContext<{ params: Params; routeId: string } | null>(
|
|
34
|
-
null,
|
|
35
|
-
);
|
|
36
|
-
const FormContext = createContext<
|
|
37
|
-
((input?: unknown) => Promise<DataResult<unknown>>) | null
|
|
38
|
-
>(null);
|
|
39
|
-
|
|
40
|
-
interface RouterProviderProps extends PropsWithChildren {
|
|
41
|
-
initialMatches?: readonly { params?: Params; routeId: string }[];
|
|
42
|
-
router: ResourceRouter;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function RouterProvider({
|
|
46
|
-
children,
|
|
47
|
-
initialMatches = EMPTY_MATCHES,
|
|
48
|
-
router,
|
|
49
|
-
}: RouterProviderProps): import("react").JSX.Element {
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
for (const match of initialMatches) {
|
|
52
|
-
void router.load(match.routeId, match.params ?? {});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return () => router.dispose();
|
|
56
|
-
}, [initialMatches, router]);
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<RouterContext.Provider value={router}>{children}</RouterContext.Provider>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
interface RouteProps extends PropsWithChildren {
|
|
64
|
-
params?: Params;
|
|
65
|
-
persistent?: boolean;
|
|
66
|
-
routeId: string;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function Route({
|
|
70
|
-
children,
|
|
71
|
-
params = {},
|
|
72
|
-
persistent = false,
|
|
73
|
-
routeId,
|
|
74
|
-
}: RouteProps): import("react").JSX.Element {
|
|
75
|
-
const router = useRouter();
|
|
76
|
-
const stableParams = useStableParams(params);
|
|
77
|
-
const state = useRouteState(routeId, stableParams, true);
|
|
78
|
-
const route = router.getRoute(routeId) as ResourceRouteModule | null;
|
|
79
|
-
const retry = useCallback(
|
|
80
|
-
() => void router.retry(routeId, stableParams),
|
|
81
|
-
[routeId, router, stableParams],
|
|
82
|
-
);
|
|
83
|
-
const contextValue = useMemo(
|
|
84
|
-
() => ({ params: stableParams, routeId }),
|
|
85
|
-
[routeId, stableParams],
|
|
86
|
-
);
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
if (persistent) router.persist(routeId, stableParams);
|
|
89
|
-
}, [persistent, routeId, router, stableParams]);
|
|
90
|
-
let content: ReactNode = children;
|
|
91
|
-
|
|
92
|
-
if (children === undefined && route?.default) {
|
|
93
|
-
const RouteComponent = route.default;
|
|
94
|
-
content = <RouteComponent />;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (state.unexpectedError && route?.ErrorBoundary) {
|
|
98
|
-
const ErrorBoundary = route.ErrorBoundary;
|
|
99
|
-
content = <ErrorBoundary retry={retry} />;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
!state.unexpectedError &&
|
|
104
|
-
!state.loaderInitialized &&
|
|
105
|
-
route?.HydrateFallback
|
|
106
|
-
) {
|
|
107
|
-
const HydrateFallback = route.HydrateFallback;
|
|
108
|
-
content = <HydrateFallback />;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
<RouteContext.Provider value={contextValue}>
|
|
113
|
-
<RenderErrorBoundary
|
|
114
|
-
onRetry={retry}
|
|
115
|
-
resetKey={`${routeId}:${JSON.stringify(stableParams)}`}
|
|
116
|
-
{...(route?.ErrorBoundary ? { fallback: route.ErrorBoundary } : {})}
|
|
117
|
-
>
|
|
118
|
-
{content}
|
|
119
|
-
</RenderErrorBoundary>
|
|
120
|
-
</RouteContext.Provider>
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function useLoaderData<Data>(): Data | null {
|
|
125
|
-
const route = useCurrentRoute();
|
|
126
|
-
|
|
127
|
-
return useRouteLoaderData<Data>(route.routeId, route.params);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function useRouteLoaderData<Data>(
|
|
131
|
-
routeId: string,
|
|
132
|
-
params: Params = {},
|
|
133
|
-
): Data | null {
|
|
134
|
-
const state = useRouteState(routeId, useStableParams(params), true);
|
|
135
|
-
|
|
136
|
-
return state.loaderData as Data | null;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function useActionData<Data>(): Data | null {
|
|
140
|
-
const route = useCurrentRoute();
|
|
141
|
-
const state = useRouteState(route.routeId, route.params, false);
|
|
142
|
-
|
|
143
|
-
return state.actionData as Data | null;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function useNavigation(): { state: NavigationState } {
|
|
147
|
-
const route = useCurrentRoute();
|
|
148
|
-
const state = useRouteState(route.routeId, route.params, false);
|
|
149
|
-
|
|
150
|
-
return { state: state.navigationState };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export function useRevalidator(): {
|
|
154
|
-
revalidate: () => Promise<DataResult<unknown>>;
|
|
155
|
-
state: string;
|
|
156
|
-
} {
|
|
157
|
-
const route = useCurrentRoute();
|
|
158
|
-
const router = useRouter();
|
|
159
|
-
const state = useRouteState(route.routeId, route.params, false);
|
|
160
|
-
|
|
161
|
-
return useMemo(
|
|
162
|
-
() => ({
|
|
163
|
-
revalidate: () => router.load(route.routeId, route.params, true),
|
|
164
|
-
state: state.navigationState === "loading" ? "loading" : "idle",
|
|
165
|
-
}),
|
|
166
|
-
[route, router, state.navigationState],
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
interface FetcherOptions {
|
|
171
|
-
params?: Params;
|
|
172
|
-
routeId?: string;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
interface FetcherTarget {
|
|
176
|
-
params?: Params;
|
|
177
|
-
routeId?: string;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
interface FormProps extends PropsWithChildren {
|
|
181
|
-
action?: string;
|
|
182
|
-
input?: unknown;
|
|
183
|
-
params?: Params;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export function Form({
|
|
187
|
-
action,
|
|
188
|
-
children,
|
|
189
|
-
input,
|
|
190
|
-
params,
|
|
191
|
-
}: FormProps): import("react").JSX.Element {
|
|
192
|
-
const currentRoute = useContext(RouteContext);
|
|
193
|
-
const router = useRouter();
|
|
194
|
-
const routeId = action ?? currentRoute?.routeId ?? "";
|
|
195
|
-
const routeParams = useStableParams(params ?? currentRoute?.params ?? {});
|
|
196
|
-
const submit = useCallback(
|
|
197
|
-
(override?: unknown) =>
|
|
198
|
-
router.submit(
|
|
199
|
-
routeId,
|
|
200
|
-
override === undefined ? input : override,
|
|
201
|
-
routeParams,
|
|
202
|
-
),
|
|
203
|
-
[input, routeId, routeParams, router],
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
if (!routeId) throw new Error("Form requires an action or a parent Route.");
|
|
207
|
-
|
|
208
|
-
return <FormContext.Provider value={submit}>{children}</FormContext.Provider>;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export function useSubmit(): (input?: unknown) => Promise<DataResult<unknown>> {
|
|
212
|
-
const submit = useContext(FormContext);
|
|
213
|
-
|
|
214
|
-
if (!submit) throw new Error("useSubmit must be used inside Form.");
|
|
215
|
-
|
|
216
|
-
return submit;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export function useFetcher<Data = unknown>(
|
|
220
|
-
options: FetcherOptions = {},
|
|
221
|
-
): readonly [
|
|
222
|
-
{ data: Data | null; error: string; state: NavigationState },
|
|
223
|
-
{
|
|
224
|
-
Form: ({
|
|
225
|
-
children,
|
|
226
|
-
input,
|
|
227
|
-
}: Pick<FormProps, "children" | "input">) => import("react").JSX.Element;
|
|
228
|
-
load: (target?: FetcherTarget) => Promise<DataResult<Data>>;
|
|
229
|
-
submit: (
|
|
230
|
-
input: unknown,
|
|
231
|
-
target?: FetcherTarget,
|
|
232
|
-
) => Promise<DataResult<Data>>;
|
|
233
|
-
},
|
|
234
|
-
] {
|
|
235
|
-
const currentRoute = useContext(RouteContext);
|
|
236
|
-
const router = useRouter();
|
|
237
|
-
const routeId = options.routeId ?? currentRoute?.routeId ?? "";
|
|
238
|
-
const params = useStableParams(options.params ?? currentRoute?.params ?? {});
|
|
239
|
-
const [data, setData] = useState<Data | null>(null);
|
|
240
|
-
const [error, setError] = useState("");
|
|
241
|
-
const [state, setState] = useState<NavigationState>("idle");
|
|
242
|
-
const controller = useRef<AbortController | null>(null);
|
|
243
|
-
useEffect(
|
|
244
|
-
() => () => {
|
|
245
|
-
controller.current?.abort();
|
|
246
|
-
},
|
|
247
|
-
[],
|
|
248
|
-
);
|
|
249
|
-
const run = useCallback(
|
|
250
|
-
async (mutating: boolean, input: unknown, target: FetcherTarget) => {
|
|
251
|
-
controller.current?.abort();
|
|
252
|
-
|
|
253
|
-
const nextController = new AbortController();
|
|
254
|
-
const { signal } = nextController;
|
|
255
|
-
const targetId = target.routeId ?? routeId;
|
|
256
|
-
const targetParams = target.params ?? params;
|
|
257
|
-
|
|
258
|
-
controller.current = nextController;
|
|
259
|
-
setError("");
|
|
260
|
-
setState(mutating ? "submitting" : "loading");
|
|
261
|
-
|
|
262
|
-
const result = await (mutating
|
|
263
|
-
? router.fetchAction<Data>(targetId, input, targetParams, signal)
|
|
264
|
-
: router.fetchLoader<Data>(targetId, targetParams, signal));
|
|
265
|
-
|
|
266
|
-
if (signal.aborted) return result;
|
|
267
|
-
|
|
268
|
-
controller.current = null;
|
|
269
|
-
setData(result.data);
|
|
270
|
-
setError(result.error);
|
|
271
|
-
setState("idle");
|
|
272
|
-
|
|
273
|
-
if (result.unexpected && currentRoute) {
|
|
274
|
-
router.reportUnexpected(currentRoute.routeId, currentRoute.params);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return result;
|
|
278
|
-
},
|
|
279
|
-
[currentRoute, params, routeId, router],
|
|
280
|
-
);
|
|
281
|
-
const submit = useCallback(
|
|
282
|
-
(input: unknown, target: FetcherTarget = {}) => run(true, input, target),
|
|
283
|
-
[run],
|
|
284
|
-
);
|
|
285
|
-
const load = useCallback(
|
|
286
|
-
(target: FetcherTarget = {}) => run(false, undefined, target),
|
|
287
|
-
[run],
|
|
288
|
-
);
|
|
289
|
-
const BoundForm = useCallback(
|
|
290
|
-
({ children, input }: Pick<FormProps, "children" | "input">) => (
|
|
291
|
-
<FormContext.Provider
|
|
292
|
-
value={(override) => submit(override === undefined ? input : override)}
|
|
293
|
-
>
|
|
294
|
-
{children}
|
|
295
|
-
</FormContext.Provider>
|
|
296
|
-
),
|
|
297
|
-
[submit],
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
if (!routeId)
|
|
301
|
-
throw new Error("useFetcher requires a routeId or a parent Route.");
|
|
302
|
-
|
|
303
|
-
const fetcherState = useMemo(
|
|
304
|
-
() => ({ data, error, state }),
|
|
305
|
-
[data, error, state],
|
|
306
|
-
);
|
|
307
|
-
const fetcherOperations = useMemo(
|
|
308
|
-
() => ({ Form: BoundForm, load, submit }),
|
|
309
|
-
[BoundForm, load, submit],
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
return [fetcherState, fetcherOperations] as const;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
export function useRouter(): ResourceRouter {
|
|
316
|
-
const router = useContext(RouterContext);
|
|
317
|
-
|
|
318
|
-
if (!router) throw new Error("RouterProvider is missing.");
|
|
319
|
-
|
|
320
|
-
return router;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
function useCurrentRoute() {
|
|
324
|
-
const route = useContext(RouteContext);
|
|
325
|
-
|
|
326
|
-
if (!route) throw new Error("This hook requires a parent Route.");
|
|
327
|
-
|
|
328
|
-
return route;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function useRouteState(routeId: string, params: Params, loadOnMount: boolean) {
|
|
332
|
-
const router = useRouter();
|
|
333
|
-
const subscribe = useCallback(
|
|
334
|
-
(listener: () => void) => router.subscribe(routeId, params, listener),
|
|
335
|
-
[params, routeId, router],
|
|
336
|
-
);
|
|
337
|
-
const getSnapshot = useCallback(
|
|
338
|
-
() => router.getSnapshot(routeId, params),
|
|
339
|
-
[params, routeId, router],
|
|
340
|
-
);
|
|
341
|
-
const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
342
|
-
useEffect(() => {
|
|
343
|
-
if (loadOnMount) void router.load(routeId, params);
|
|
344
|
-
}, [loadOnMount, params, routeId, router]);
|
|
345
|
-
|
|
346
|
-
return state;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function useStableParams(params: Params) {
|
|
350
|
-
const key = JSON.stringify(
|
|
351
|
-
Object.entries(params).sort(([left], [right]) => left.localeCompare(right)),
|
|
352
|
-
);
|
|
353
|
-
const ref = useRef({ key, value: params });
|
|
354
|
-
|
|
355
|
-
if (ref.current.key !== key) ref.current = { key, value: params };
|
|
356
|
-
|
|
357
|
-
return ref.current.value;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
interface RenderErrorBoundaryProps extends PropsWithChildren {
|
|
361
|
-
fallback?: ComponentType<{ retry: () => void }>;
|
|
362
|
-
onRetry: () => void;
|
|
363
|
-
resetKey: string;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
class RenderErrorBoundary extends Component<
|
|
367
|
-
RenderErrorBoundaryProps,
|
|
368
|
-
{ error: Error | null }
|
|
369
|
-
> {
|
|
370
|
-
override state = { error: null };
|
|
371
|
-
|
|
372
|
-
static getDerivedStateFromError(error: Error) {
|
|
373
|
-
return { error };
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
override componentDidUpdate(previousProps: RenderErrorBoundaryProps) {
|
|
377
|
-
if (this.state.error && previousProps.resetKey !== this.props.resetKey) {
|
|
378
|
-
this.setState({ error: null });
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
override render() {
|
|
383
|
-
if (this.state.error && this.props.fallback) {
|
|
384
|
-
const ErrorBoundary = this.props.fallback;
|
|
385
|
-
|
|
386
|
-
return (
|
|
387
|
-
<ErrorBoundary
|
|
388
|
-
retry={() => {
|
|
389
|
-
this.setState({ error: null });
|
|
390
|
-
this.props.onRetry();
|
|
391
|
-
}}
|
|
392
|
-
/>
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
if (this.state.error) throw this.state.error;
|
|
397
|
-
|
|
398
|
-
return this.props.children;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
export type { NavigationState, RouteState };
|
|
403
|
-
|
|
404
|
-
const EMPTY_MATCHES: readonly { params?: Params; routeId: string }[] = [];
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export type Params = Readonly<Record<string, string>>;
|
|
2
|
-
export interface LoaderFunctionArgs {
|
|
3
|
-
params: Params;
|
|
4
|
-
signal: AbortSignal;
|
|
5
|
-
}
|
|
6
|
-
export interface ActionFunctionArgs<Input = unknown> {
|
|
7
|
-
input: Input;
|
|
8
|
-
params: Params;
|
|
9
|
-
signal: AbortSignal;
|
|
10
|
-
}
|
|
11
|
-
export interface DataResult<Data> {
|
|
12
|
-
data: Data | null;
|
|
13
|
-
error: string;
|
|
14
|
-
unexpected?: true;
|
|
15
|
-
}
|
|
16
|
-
export interface ResourceModule {
|
|
17
|
-
action?: (args: ActionFunctionArgs) => Promise<DataResult<unknown>>;
|
|
18
|
-
loader?: (args: LoaderFunctionArgs) => Promise<DataResult<unknown>>;
|
|
19
|
-
shouldRevalidate?: (args: ShouldRevalidateFunctionArgs) => boolean;
|
|
20
|
-
}
|
|
21
|
-
export interface ShouldRevalidateFunctionArgs {
|
|
22
|
-
actionResult: DataResult<unknown>;
|
|
23
|
-
defaultShouldRevalidate: boolean;
|
|
24
|
-
params: Params;
|
|
25
|
-
}
|
|
26
|
-
export type NavigationState = "idle" | "loading" | "submitting";
|
|
27
|
-
export interface RouteState {
|
|
28
|
-
actionData: unknown;
|
|
29
|
-
actionError: string;
|
|
30
|
-
actionState: "idle" | "submitting";
|
|
31
|
-
loaderData: unknown;
|
|
32
|
-
loaderError: string;
|
|
33
|
-
loaderInitialized: boolean;
|
|
34
|
-
loaderState: "idle" | "loading";
|
|
35
|
-
navigationState: NavigationState;
|
|
36
|
-
unexpectedError: boolean;
|
|
37
|
-
}
|
package/dist/core/resources.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { DataResult, Params, ResourceModule, RouteState } from "./resource-types.ts";
|
|
2
|
-
export declare class ResourceRouter {
|
|
3
|
-
#private;
|
|
4
|
-
constructor(routes: ReadonlyMap<string, ResourceModule>);
|
|
5
|
-
dispose(): void;
|
|
6
|
-
getRoute(routeId: string): ResourceModule | null;
|
|
7
|
-
getSnapshot(routeId: string, params: Params): RouteState;
|
|
8
|
-
hydrateRoute<Data>(routeId: string, data: Data, params?: Params): void;
|
|
9
|
-
persist(routeId: string, params?: Params): void;
|
|
10
|
-
disposeRoute(routeId: string, params?: Params): void;
|
|
11
|
-
load<Data>(routeId: string, params?: Params, force?: boolean): Promise<DataResult<Data>>;
|
|
12
|
-
subscribe(routeId: string, params: Params, listener: () => void): () => void;
|
|
13
|
-
submit<Data>(routeId: string, input: unknown, params?: Params): Promise<DataResult<Data>>;
|
|
14
|
-
fetchLoader<Data>(routeId: string, params: Params, signal: AbortSignal): Promise<DataResult<Data>>;
|
|
15
|
-
fetchAction<Data>(routeId: string, input: unknown, params: Params, signal: AbortSignal): Promise<DataResult<Data>>;
|
|
16
|
-
retry(routeId: string, params: Params): Promise<DataResult<unknown>>;
|
|
17
|
-
reportUnexpected(routeId: string, params: Params): void;
|
|
18
|
-
}
|
|
19
|
-
export declare function createResourceRouter(routes: ReadonlyMap<string, ResourceModule>): ResourceRouter;
|