@kasperrt/smolter 0.4.3 → 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/prepare-routes.ts +50 -0
- package/.generated/core/presentation.ts +1 -1
- package/.generated/preact/client.tsx +1 -26
- package/.generated/preact/deferred-hydration.ts +1 -98
- package/.generated/preact/index.ts +6 -1
- package/.generated/preact/navigation.tsx +13 -5
- package/.generated/preact/root-data.ts +1 -45
- package/.generated/preact/router.tsx +2 -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 +17 -1
- 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/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 -253
- package/.generated/server/dispatch.ts +87 -0
- package/.generated/server/index.ts +2 -0
- 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 +10 -0
- package/README.md +41 -41
- 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/prepare-routes.d.ts +7 -0
- package/dist/core/prepare-routes.js +28 -0
- package/dist/core/presentation.js +1 -1
- package/dist/preact/client.js +5 -26
- package/dist/preact/deferred-hydration.d.ts +1 -10
- package/dist/preact/document.js +2 -2
- package/dist/preact/index.d.ts +1 -1
- package/dist/preact/index.js +1 -1
- package/dist/preact/navigation-state.js +1 -1
- package/dist/preact/navigation.js +7 -5
- package/dist/preact/root-data.d.ts +1 -8
- package/dist/preact/route-hooks.js +1 -1
- package/dist/preact/router.d.ts +2 -2
- package/dist/preact/router.js +2 -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 +7 -1
- package/dist/react/index.js +6 -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/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 -8
- package/dist/server/application.js +9 -156
- package/dist/server/dispatch.d.ts +5 -0
- package/dist/server/dispatch.js +50 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +2 -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 +18 -10
- package/.generated/core/resource-types.ts +0 -48
- package/.generated/core/resources.ts +0 -446
- package/.generated/react/data.ts +0 -29
- package/.generated/react/resources/components.tsx +0 -416
- package/dist/core/resource-types.d.ts +0 -41
- package/dist/core/resources.d.ts +0 -21
- package/dist/core/resources.js +0 -347
- package/dist/react/data.d.ts +0 -9
- package/dist/react/data.js +0 -3
- package/dist/react/link.js +0 -27
- package/dist/react/resources/components.d.ts +0 -76
- package/dist/react/resources/components.js +0 -250
package/dist/core/resources.js
DELETED
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
import { safeWrapAsync } from "./errors.js";
|
|
2
|
-
//#region .generated/core/resources.ts
|
|
3
|
-
var IDLE_ROUTE_STATE = {
|
|
4
|
-
actionData: null,
|
|
5
|
-
actionError: "",
|
|
6
|
-
actionState: "idle",
|
|
7
|
-
loaderData: null,
|
|
8
|
-
loaderError: "",
|
|
9
|
-
loaderInitialized: false,
|
|
10
|
-
loaderState: "idle",
|
|
11
|
-
navigationState: "idle",
|
|
12
|
-
unexpectedError: false
|
|
13
|
-
};
|
|
14
|
-
/** Manage keyed resource reads, submissions, subscriptions and cancellation independently of navigation. */
|
|
15
|
-
var ResourceRouter = class {
|
|
16
|
-
#cleanupTimers = /* @__PURE__ */ new Map();
|
|
17
|
-
#controllers = /* @__PURE__ */ new Map();
|
|
18
|
-
#inFlightLoads = /* @__PURE__ */ new Map();
|
|
19
|
-
#listeners = /* @__PURE__ */ new Map();
|
|
20
|
-
#persistentRoutes = /* @__PURE__ */ new Set();
|
|
21
|
-
#routes;
|
|
22
|
-
#states = /* @__PURE__ */ new Map();
|
|
23
|
-
constructor(routes) {
|
|
24
|
-
this.#routes = routes;
|
|
25
|
-
}
|
|
26
|
-
dispose() {
|
|
27
|
-
for (const controller of this.#controllers.values()) controller.abort();
|
|
28
|
-
this.#controllers.clear();
|
|
29
|
-
for (const timer of this.#cleanupTimers.values()) clearTimeout(timer);
|
|
30
|
-
this.#cleanupTimers.clear();
|
|
31
|
-
this.#inFlightLoads.clear();
|
|
32
|
-
this.#listeners.clear();
|
|
33
|
-
this.#persistentRoutes.clear();
|
|
34
|
-
}
|
|
35
|
-
getRoute(routeId) {
|
|
36
|
-
return this.#routes.get(routeId) ?? null;
|
|
37
|
-
}
|
|
38
|
-
getSnapshot(routeId, params) {
|
|
39
|
-
return this.#states.get(createRouteKey(routeId, params)) ?? IDLE_ROUTE_STATE;
|
|
40
|
-
}
|
|
41
|
-
hydrateRoute(routeId, data, params = {}) {
|
|
42
|
-
const routeKey = createRouteKey(routeId, params);
|
|
43
|
-
const currentState = this.#states.get(routeKey) ?? IDLE_ROUTE_STATE;
|
|
44
|
-
this.#setState(routeKey, {
|
|
45
|
-
...currentState,
|
|
46
|
-
loaderData: data,
|
|
47
|
-
loaderError: "",
|
|
48
|
-
loaderInitialized: true,
|
|
49
|
-
loaderState: "idle",
|
|
50
|
-
navigationState: currentState.actionState === "submitting" ? "submitting" : "idle",
|
|
51
|
-
unexpectedError: false
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
persist(routeId, params = {}) {
|
|
55
|
-
const routeKey = createRouteKey(routeId, params);
|
|
56
|
-
this.#persistentRoutes.add(routeKey);
|
|
57
|
-
const cleanupTimer = this.#cleanupTimers.get(routeKey);
|
|
58
|
-
if (!cleanupTimer) return;
|
|
59
|
-
clearTimeout(cleanupTimer);
|
|
60
|
-
this.#cleanupTimers.delete(routeKey);
|
|
61
|
-
}
|
|
62
|
-
disposeRoute(routeId, params = {}) {
|
|
63
|
-
this.#disposeRouteKey(createRouteKey(routeId, params));
|
|
64
|
-
}
|
|
65
|
-
#disposeRouteKey(routeKey) {
|
|
66
|
-
this.#persistentRoutes.delete(routeKey);
|
|
67
|
-
const cleanupTimer = this.#cleanupTimers.get(routeKey);
|
|
68
|
-
if (cleanupTimer) clearTimeout(cleanupTimer);
|
|
69
|
-
this.#cleanupTimers.delete(routeKey);
|
|
70
|
-
this.#controllers.get(routeKey)?.abort();
|
|
71
|
-
this.#controllers.get(`${routeKey}:action`)?.abort();
|
|
72
|
-
this.#controllers.delete(routeKey);
|
|
73
|
-
this.#controllers.delete(`${routeKey}:action`);
|
|
74
|
-
this.#inFlightLoads.delete(routeKey);
|
|
75
|
-
this.#states.delete(routeKey);
|
|
76
|
-
this.#notify(routeKey);
|
|
77
|
-
}
|
|
78
|
-
load(routeId, params = {}, force = false) {
|
|
79
|
-
const routeKey = createRouteKey(routeId, params);
|
|
80
|
-
const route = this.#routes.get(routeId);
|
|
81
|
-
if (!route?.loader) return Promise.resolve({
|
|
82
|
-
data: null,
|
|
83
|
-
error: "Route loader not found."
|
|
84
|
-
});
|
|
85
|
-
const currentState = this.#states.get(routeKey);
|
|
86
|
-
if (!force && currentState?.loaderInitialized) return Promise.resolve({
|
|
87
|
-
data: currentState?.loaderData,
|
|
88
|
-
error: currentState?.loaderError ?? ""
|
|
89
|
-
});
|
|
90
|
-
const currentLoad = this.#inFlightLoads.get(routeKey);
|
|
91
|
-
if (force && currentLoad) {
|
|
92
|
-
this.#controllers.get(routeKey)?.abort();
|
|
93
|
-
this.#inFlightLoads.delete(routeKey);
|
|
94
|
-
}
|
|
95
|
-
if (!force && currentLoad) return currentLoad;
|
|
96
|
-
const controller = this.#replaceController(routeKey);
|
|
97
|
-
this.#setState(routeKey, {
|
|
98
|
-
...currentState ?? IDLE_ROUTE_STATE,
|
|
99
|
-
loaderError: "",
|
|
100
|
-
loaderState: "loading",
|
|
101
|
-
navigationState: currentState?.actionState === "submitting" ? "submitting" : "loading",
|
|
102
|
-
unexpectedError: false
|
|
103
|
-
});
|
|
104
|
-
const load = this.#runLoader(route, routeKey, params, controller);
|
|
105
|
-
this.#inFlightLoads.set(routeKey, load);
|
|
106
|
-
return load;
|
|
107
|
-
}
|
|
108
|
-
subscribe(routeId, params, listener) {
|
|
109
|
-
const routeKey = createRouteKey(routeId, params);
|
|
110
|
-
const cleanupTimer = this.#cleanupTimers.get(routeKey);
|
|
111
|
-
if (cleanupTimer) {
|
|
112
|
-
clearTimeout(cleanupTimer);
|
|
113
|
-
this.#cleanupTimers.delete(routeKey);
|
|
114
|
-
}
|
|
115
|
-
const listeners = this.#listeners.get(routeKey) ?? /* @__PURE__ */ new Set();
|
|
116
|
-
listeners.add(listener);
|
|
117
|
-
this.#listeners.set(routeKey, listeners);
|
|
118
|
-
return () => {
|
|
119
|
-
if (!listeners.delete(listener) || listeners.size > 0) return;
|
|
120
|
-
this.#listeners.delete(routeKey);
|
|
121
|
-
if (this.#persistentRoutes.has(routeKey)) return;
|
|
122
|
-
const timer = setTimeout(() => this.#disposeRouteKey(routeKey), routeCleanupGraceMs);
|
|
123
|
-
this.#cleanupTimers.set(routeKey, timer);
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
async submit(routeId, input, params = {}) {
|
|
127
|
-
const routeKey = createRouteKey(routeId, params);
|
|
128
|
-
const route = this.#routes.get(routeId);
|
|
129
|
-
if (!route?.action) return {
|
|
130
|
-
data: null,
|
|
131
|
-
error: "Route action not found."
|
|
132
|
-
};
|
|
133
|
-
const controllerKey = `${routeKey}:action`;
|
|
134
|
-
const controller = this.#replaceController(controllerKey);
|
|
135
|
-
const currentState = this.#states.get(routeKey) ?? IDLE_ROUTE_STATE;
|
|
136
|
-
this.#setState(routeKey, {
|
|
137
|
-
...currentState,
|
|
138
|
-
actionError: "",
|
|
139
|
-
actionState: "submitting",
|
|
140
|
-
navigationState: "submitting",
|
|
141
|
-
unexpectedError: false
|
|
142
|
-
});
|
|
143
|
-
const { error, data: result } = await safeWrapAsync(() => route.action?.({
|
|
144
|
-
input,
|
|
145
|
-
params,
|
|
146
|
-
signal: controller.signal
|
|
147
|
-
}));
|
|
148
|
-
if (this.#controllers.get(controllerKey) === controller) this.#controllers.delete(controllerKey);
|
|
149
|
-
if (controller.signal.aborted) return {
|
|
150
|
-
data: null,
|
|
151
|
-
error: ""
|
|
152
|
-
};
|
|
153
|
-
const latestState = this.#states.get(routeKey) ?? IDLE_ROUTE_STATE;
|
|
154
|
-
if (error || !result) {
|
|
155
|
-
const publicError = "The request could not be completed.";
|
|
156
|
-
this.#setState(routeKey, {
|
|
157
|
-
...latestState,
|
|
158
|
-
actionData: null,
|
|
159
|
-
actionError: publicError,
|
|
160
|
-
actionState: "idle",
|
|
161
|
-
navigationState: latestState.loaderState === "loading" ? "loading" : "idle",
|
|
162
|
-
unexpectedError: true
|
|
163
|
-
});
|
|
164
|
-
return {
|
|
165
|
-
data: null,
|
|
166
|
-
error: publicError,
|
|
167
|
-
unexpected: true
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
this.#setState(routeKey, {
|
|
171
|
-
...latestState,
|
|
172
|
-
actionData: result.data,
|
|
173
|
-
actionError: result.error,
|
|
174
|
-
actionState: "idle",
|
|
175
|
-
navigationState: latestState.loaderState === "loading" ? "loading" : "idle",
|
|
176
|
-
unexpectedError: false
|
|
177
|
-
});
|
|
178
|
-
const actionResult = {
|
|
179
|
-
data: result.data,
|
|
180
|
-
error: result.error
|
|
181
|
-
};
|
|
182
|
-
const { error: revalidationError, data: shouldRevalidate } = await safeWrapAsync(() => route.shouldRevalidate?.({
|
|
183
|
-
actionResult: result,
|
|
184
|
-
defaultShouldRevalidate: Boolean(route.loader),
|
|
185
|
-
params
|
|
186
|
-
}) ?? Boolean(route.loader));
|
|
187
|
-
if (revalidationError) {
|
|
188
|
-
const publicError = "The request could not be completed.";
|
|
189
|
-
this.#setState(routeKey, {
|
|
190
|
-
...this.#states.get(routeKey) ?? IDLE_ROUTE_STATE,
|
|
191
|
-
actionError: publicError,
|
|
192
|
-
actionState: "idle",
|
|
193
|
-
unexpectedError: true
|
|
194
|
-
});
|
|
195
|
-
return {
|
|
196
|
-
data: null,
|
|
197
|
-
error: publicError,
|
|
198
|
-
unexpected: true
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
if (shouldRevalidate) await this.load(routeId, params, true);
|
|
202
|
-
return actionResult;
|
|
203
|
-
}
|
|
204
|
-
async fetchLoader(routeId, params, signal) {
|
|
205
|
-
const route = this.#routes.get(routeId);
|
|
206
|
-
if (!route?.loader) return {
|
|
207
|
-
data: null,
|
|
208
|
-
error: "Route loader not found."
|
|
209
|
-
};
|
|
210
|
-
const { error, data: result } = await safeWrapAsync(() => route.loader?.({
|
|
211
|
-
params,
|
|
212
|
-
signal
|
|
213
|
-
}));
|
|
214
|
-
if (signal.aborted) return {
|
|
215
|
-
data: null,
|
|
216
|
-
error: ""
|
|
217
|
-
};
|
|
218
|
-
if (error || !result) return {
|
|
219
|
-
data: null,
|
|
220
|
-
error: "The route could not be loaded.",
|
|
221
|
-
unexpected: true
|
|
222
|
-
};
|
|
223
|
-
return result;
|
|
224
|
-
}
|
|
225
|
-
async fetchAction(routeId, input, params, signal) {
|
|
226
|
-
const route = this.#routes.get(routeId);
|
|
227
|
-
if (!route?.action) return {
|
|
228
|
-
data: null,
|
|
229
|
-
error: "Route action not found."
|
|
230
|
-
};
|
|
231
|
-
const { error, data: result } = await safeWrapAsync(() => route.action?.({
|
|
232
|
-
input,
|
|
233
|
-
params,
|
|
234
|
-
signal
|
|
235
|
-
}));
|
|
236
|
-
if (signal.aborted) return {
|
|
237
|
-
data: null,
|
|
238
|
-
error: ""
|
|
239
|
-
};
|
|
240
|
-
if (error || !result) return {
|
|
241
|
-
data: null,
|
|
242
|
-
error: "The request could not be completed.",
|
|
243
|
-
unexpected: true
|
|
244
|
-
};
|
|
245
|
-
const { error: revalidationError, data: shouldRevalidate } = await safeWrapAsync(() => route.shouldRevalidate?.({
|
|
246
|
-
actionResult: result,
|
|
247
|
-
defaultShouldRevalidate: Boolean(route.loader),
|
|
248
|
-
params
|
|
249
|
-
}) ?? Boolean(route.loader));
|
|
250
|
-
if (signal.aborted) return {
|
|
251
|
-
data: null,
|
|
252
|
-
error: ""
|
|
253
|
-
};
|
|
254
|
-
if (revalidationError) return {
|
|
255
|
-
data: null,
|
|
256
|
-
error: "The request could not be completed.",
|
|
257
|
-
unexpected: true
|
|
258
|
-
};
|
|
259
|
-
if (shouldRevalidate) await this.load(routeId, params, true);
|
|
260
|
-
return result;
|
|
261
|
-
}
|
|
262
|
-
retry(routeId, params) {
|
|
263
|
-
const routeKey = createRouteKey(routeId, params);
|
|
264
|
-
this.#states.set(routeKey, IDLE_ROUTE_STATE);
|
|
265
|
-
this.#notify(routeKey);
|
|
266
|
-
return this.load(routeId, params, true);
|
|
267
|
-
}
|
|
268
|
-
reportUnexpected(routeId, params) {
|
|
269
|
-
const routeKey = createRouteKey(routeId, params);
|
|
270
|
-
const currentState = this.#states.get(routeKey) ?? IDLE_ROUTE_STATE;
|
|
271
|
-
this.#setState(routeKey, {
|
|
272
|
-
...currentState,
|
|
273
|
-
unexpectedError: true
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
async #runLoader(route, routeKey, params, controller) {
|
|
277
|
-
const { error, data: result } = await safeWrapAsync(() => route.loader?.({
|
|
278
|
-
params,
|
|
279
|
-
signal: controller.signal
|
|
280
|
-
}) ?? Promise.resolve({
|
|
281
|
-
data: null,
|
|
282
|
-
error: ""
|
|
283
|
-
}));
|
|
284
|
-
if (this.#controllers.get(routeKey) === controller) {
|
|
285
|
-
this.#controllers.delete(routeKey);
|
|
286
|
-
this.#inFlightLoads.delete(routeKey);
|
|
287
|
-
}
|
|
288
|
-
if (controller.signal.aborted) return {
|
|
289
|
-
data: null,
|
|
290
|
-
error: ""
|
|
291
|
-
};
|
|
292
|
-
if (error || !result) {
|
|
293
|
-
const publicError = "The route could not be loaded.";
|
|
294
|
-
this.#setState(routeKey, {
|
|
295
|
-
actionData: null,
|
|
296
|
-
actionError: "",
|
|
297
|
-
actionState: "idle",
|
|
298
|
-
loaderData: null,
|
|
299
|
-
loaderError: publicError,
|
|
300
|
-
loaderInitialized: true,
|
|
301
|
-
loaderState: "idle",
|
|
302
|
-
navigationState: "idle",
|
|
303
|
-
unexpectedError: true
|
|
304
|
-
});
|
|
305
|
-
return {
|
|
306
|
-
data: null,
|
|
307
|
-
error: publicError,
|
|
308
|
-
unexpected: true
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
const currentState = this.#states.get(routeKey) ?? IDLE_ROUTE_STATE;
|
|
312
|
-
this.#setState(routeKey, {
|
|
313
|
-
...currentState,
|
|
314
|
-
loaderData: result.data,
|
|
315
|
-
loaderError: result.error,
|
|
316
|
-
loaderInitialized: true,
|
|
317
|
-
loaderState: "idle",
|
|
318
|
-
navigationState: currentState.actionState === "submitting" ? "submitting" : "idle",
|
|
319
|
-
unexpectedError: false
|
|
320
|
-
});
|
|
321
|
-
return result;
|
|
322
|
-
}
|
|
323
|
-
#replaceController(key) {
|
|
324
|
-
this.#controllers.get(key)?.abort();
|
|
325
|
-
const controller = new AbortController();
|
|
326
|
-
this.#controllers.set(key, controller);
|
|
327
|
-
return controller;
|
|
328
|
-
}
|
|
329
|
-
#setState(routeKey, state) {
|
|
330
|
-
this.#states.set(routeKey, state);
|
|
331
|
-
this.#notify(routeKey);
|
|
332
|
-
}
|
|
333
|
-
#notify(routeKey) {
|
|
334
|
-
for (const listener of this.#listeners.get(routeKey) ?? []) listener();
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
/** Create an independent resource-data router from registered modules; this does not manage URL history. */
|
|
338
|
-
function createResourceRouter(routes) {
|
|
339
|
-
return new ResourceRouter(routes);
|
|
340
|
-
}
|
|
341
|
-
function createRouteKey(routeId, params) {
|
|
342
|
-
const normalizedParams = Object.entries(params).sort(([left], [right]) => left.localeCompare(right));
|
|
343
|
-
return `${routeId}:${JSON.stringify(normalizedParams)}`;
|
|
344
|
-
}
|
|
345
|
-
var routeCleanupGraceMs = 100;
|
|
346
|
-
//#endregion
|
|
347
|
-
export { ResourceRouter, createResourceRouter };
|
package/dist/react/data.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Independent React resource data, forms and subscriptions.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
export type { ActionFunctionArgs as ResourceActionArgs, DataResult as ResourceResult, LoaderFunctionArgs as ResourceLoaderArgs, ShouldRevalidateFunctionArgs as ResourceRevalidationArgs, } from "../core/resource-types.ts";
|
|
7
|
-
export { createResourceRouter, ResourceRouter, } from "../core/resources.ts";
|
|
8
|
-
export type { ResourceRouteModule } from "./resources/components.tsx";
|
|
9
|
-
export { Form as ResourceForm, Route as Resource, RouterProvider as ResourceProvider, useActionData as useResourceActionData, useFetcher as useResourceFetcher, useLoaderData as useResourceData, useNavigation as useResourceNavigation, useRevalidator as useResourceRevalidator, useRouteLoaderData, useRouter as useResourceRouter, useSubmit as useResourceSubmit, } from "./resources/components.tsx";
|
package/dist/react/data.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { ResourceRouter, createResourceRouter } from "../core/resources.js";
|
|
2
|
-
import { Form, Route, RouterProvider, useActionData, useFetcher, useLoaderData, useNavigation, useRevalidator, useRouteLoaderData, useRouter, useSubmit } from "./resources/components.js";
|
|
3
|
-
export { Route as Resource, Form as ResourceForm, RouterProvider as ResourceProvider, ResourceRouter, createResourceRouter, useActionData as useResourceActionData, useLoaderData as useResourceData, useFetcher as useResourceFetcher, useNavigation as useResourceNavigation, useRevalidator as useResourceRevalidator, useRouter as useResourceRouter, useSubmit as useResourceSubmit, useRouteLoaderData };
|
package/dist/react/link.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { internalURL, navigationClick } from "../core/url.js";
|
|
2
|
-
import { createElement } from "./runtime.js";
|
|
3
|
-
import { useRouter } from "./context.js";
|
|
4
|
-
//#region .generated/react/link.ts
|
|
5
|
-
/**
|
|
6
|
-
* React components and typed data hooks. Import from @kasperrt/smolter/react.
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
/** Render an anchor that handles internal navigation and preserves native modified clicks. */
|
|
10
|
-
function Link(options) {
|
|
11
|
-
const { href, replace, onClick, ...props } = options;
|
|
12
|
-
const router = useRouter();
|
|
13
|
-
const click = (event) => {
|
|
14
|
-
onClick?.(event);
|
|
15
|
-
if (!navigationClick(event, event.currentTarget)) return;
|
|
16
|
-
if (!internalURL(router.getSnapshot().url, href)) return;
|
|
17
|
-
event.preventDefault();
|
|
18
|
-
router.navigate(href, options);
|
|
19
|
-
};
|
|
20
|
-
return createElement("a", {
|
|
21
|
-
...props,
|
|
22
|
-
href,
|
|
23
|
-
onClick: click
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
export { Link };
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource react */
|
|
2
|
-
import type { DataResult, NavigationState, Params, ResourceModule, RouteState } from "../../core/resource-types.ts";
|
|
3
|
-
import type { ResourceRouter } from "../../core/resources.ts";
|
|
4
|
-
import { type ComponentType, type PropsWithChildren } from "react";
|
|
5
|
-
/** Resource handlers with optional React content, pending UI and retry boundary. */
|
|
6
|
-
export interface ResourceRouteModule extends ResourceModule {
|
|
7
|
-
default?: ComponentType;
|
|
8
|
-
ErrorBoundary?: ComponentType<{
|
|
9
|
-
retry: () => void;
|
|
10
|
-
}>;
|
|
11
|
-
HydrateFallback?: ComponentType;
|
|
12
|
-
}
|
|
13
|
-
interface RouterProviderProps extends PropsWithChildren {
|
|
14
|
-
initialMatches?: readonly {
|
|
15
|
-
params?: Params;
|
|
16
|
-
routeId: string;
|
|
17
|
-
}[];
|
|
18
|
-
router: ResourceRouter;
|
|
19
|
-
}
|
|
20
|
-
/** Provide a resource router and load initial matches; dispose it when unmounted. */
|
|
21
|
-
export declare function RouterProvider({ children, initialMatches, router, }: RouterProviderProps): import("react").JSX.Element;
|
|
22
|
-
interface RouteProps extends PropsWithChildren {
|
|
23
|
-
params?: Params;
|
|
24
|
-
persistent?: boolean;
|
|
25
|
-
routeId: string;
|
|
26
|
-
}
|
|
27
|
-
/** Provide a resource route and render its content, loading state or retry boundary. */
|
|
28
|
-
export declare function Route({ children, params, persistent, routeId, }: RouteProps): import("react").JSX.Element;
|
|
29
|
-
/** Read the current resource route loader result. */
|
|
30
|
-
export declare function useLoaderData<Data>(): Data | null;
|
|
31
|
-
/** Read loader data for a registered resource route. */
|
|
32
|
-
export declare function useRouteLoaderData<Data>(routeId: string, params?: Params): Data | null;
|
|
33
|
-
/** Read the current resource route action result. */
|
|
34
|
-
export declare function useActionData<Data>(): Data | null;
|
|
35
|
-
/** Read the current page navigation or submission state. */
|
|
36
|
-
export declare function useNavigation(): {
|
|
37
|
-
state: NavigationState;
|
|
38
|
-
};
|
|
39
|
-
/** Return the resource route revalidation function. */
|
|
40
|
-
export declare function useRevalidator(): {
|
|
41
|
-
revalidate: () => Promise<DataResult<unknown>>;
|
|
42
|
-
state: string;
|
|
43
|
-
};
|
|
44
|
-
interface FetcherOptions {
|
|
45
|
-
params?: Params;
|
|
46
|
-
routeId?: string;
|
|
47
|
-
}
|
|
48
|
-
interface FetcherTarget {
|
|
49
|
-
params?: Params;
|
|
50
|
-
routeId?: string;
|
|
51
|
-
}
|
|
52
|
-
interface FormProps extends PropsWithChildren {
|
|
53
|
-
action?: string;
|
|
54
|
-
input?: unknown;
|
|
55
|
-
params?: Params;
|
|
56
|
-
}
|
|
57
|
-
/** Submit a resource action from a form without document navigation. */
|
|
58
|
-
export declare function Form({ action, children, input, params, }: FormProps): import("react").JSX.Element;
|
|
59
|
-
/** Return a function that submits form data through the current router. */
|
|
60
|
-
export declare function useSubmit(): (input?: unknown) => Promise<DataResult<unknown>>;
|
|
61
|
-
/** Read or mutate a resource independently of the rendered route. */
|
|
62
|
-
export declare function useFetcher<Data = unknown>(options?: FetcherOptions): readonly [
|
|
63
|
-
{
|
|
64
|
-
data: Data | null;
|
|
65
|
-
error: string;
|
|
66
|
-
state: NavigationState;
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
Form: ({ children, input, }: Pick<FormProps, "children" | "input">) => import("react").JSX.Element;
|
|
70
|
-
load: (target?: FetcherTarget) => Promise<DataResult<Data>>;
|
|
71
|
-
submit: (input: unknown, target?: FetcherTarget) => Promise<DataResult<Data>>;
|
|
72
|
-
}
|
|
73
|
-
];
|
|
74
|
-
/** Read the resource router supplied by its provider. */
|
|
75
|
-
export declare function useRouter(): ResourceRouter;
|
|
76
|
-
export type { NavigationState, RouteState };
|