eddev 2.0.0-beta.3 → 2.0.0-beta.31
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/dist/app/entry/MetaTags.d.ts +6 -0
- package/dist/app/entry/MetaTags.js +17 -0
- package/dist/app/entry/boot-admin.d.ts +1 -0
- package/dist/app/entry/{main.admin.js → boot-admin.js} +3 -5
- package/dist/app/entry/spa-root.d.ts +1 -0
- package/dist/app/entry/{Root.js → spa-root.js} +4 -4
- package/dist/app/entry/ssr-root-client.d.ts +6 -0
- package/dist/app/entry/ssr-root-client.js +16 -0
- package/dist/app/entry/ssr-root.d.ts +10 -0
- package/dist/app/entry/ssr-root.js +24 -0
- package/dist/app/lib/admin/index.d.ts +2 -2
- package/dist/app/lib/admin/index.js +2 -2
- package/dist/app/lib/admin/installFieldTypes.js +1 -1
- package/dist/app/lib/admin/runWidgets.js +1 -1
- package/dist/app/lib/blocks/ContentBlocks.js +4 -4
- package/dist/app/lib/blocks/EditableText.d.ts +1 -1
- package/dist/app/lib/blocks/EditableText.js +3 -3
- package/dist/app/lib/blocks/ErrorBoundaryFrontend.js +1 -0
- package/dist/app/lib/blocks/InnerBlocks.d.ts +13 -3
- package/dist/app/lib/blocks/InnerBlocks.js +13 -5
- package/dist/app/lib/blocks/block-utils.d.ts +2 -2
- package/dist/app/lib/blocks/block-utils.js +2 -2
- package/dist/app/lib/blocks/editor/EditorSupport.js +3 -3
- package/dist/app/lib/blocks/editor/editor-config.d.ts +1 -1
- package/dist/app/lib/blocks/editor/editor-config.js +1 -1
- package/dist/app/lib/blocks/editor/installGutenbergHooks.js +5 -5
- package/dist/app/lib/blocks/editor/usePostEditor.d.ts +1 -1
- package/dist/app/lib/blocks/index.d.ts +9 -9
- package/dist/app/lib/blocks/index.js +9 -9
- package/dist/app/lib/blocks/inline-editing.d.ts +1 -1
- package/dist/app/lib/blocks/inline-editing.js +7 -5
- package/dist/app/lib/devtools/components/BreakpointIndicator.js +5 -3
- package/dist/app/lib/devtools/components/DevUI.js +1 -1
- package/dist/app/lib/devtools/dev-tools-store.d.ts +9 -0
- package/dist/app/lib/devtools/dev-tools-store.js +8 -0
- package/dist/app/lib/devtools/hooks/useTailwind.d.ts +1078 -1079
- package/dist/app/lib/devtools/hooks/useTailwind.js +6 -3
- package/dist/app/lib/devtools/index.d.ts +1 -0
- package/dist/app/lib/devtools/index.js +1 -1
- package/dist/app/lib/devtools/loader.js +4 -4
- package/dist/app/lib/devtools/useQueryDebug.d.ts +7 -1
- package/dist/app/lib/devtools/useQueryDebug.js +5 -8
- package/dist/app/lib/dynamic/index.d.ts +1 -1
- package/dist/app/lib/dynamic/index.js +1 -1
- package/dist/app/lib/hooks/apiConfig.d.ts +3 -1
- package/dist/app/lib/hooks/apiConfig.js +9 -4
- package/dist/app/lib/hooks/index.d.ts +4 -5
- package/dist/app/lib/hooks/index.js +4 -5
- package/dist/app/lib/hooks/queryUtils.d.ts +5 -2
- package/dist/app/lib/hooks/queryUtils.js +19 -20
- package/dist/app/lib/hooks/useAppData.js +1 -1
- package/dist/app/lib/internal/index.d.ts +4 -4
- package/dist/app/lib/internal/index.js +4 -4
- package/dist/app/lib/internal/internal-store.d.ts +0 -2
- package/dist/app/lib/internal/internal-store.js +1 -3
- package/dist/app/lib/internal/read-admin-manifest.d.ts +1 -1
- package/dist/app/lib/legacy-stitches/createStitches.d.ts +21 -21
- package/dist/app/lib/legacy-stitches/createStitches.js +1 -1
- package/dist/app/lib/legacy-stitches/index.d.ts +1 -1
- package/dist/app/lib/legacy-stitches/index.js +1 -1
- package/dist/app/lib/routing/components/BackButton.d.ts +49 -0
- package/dist/app/lib/routing/components/BackButton.js +47 -0
- package/dist/app/lib/routing/components/BrowserRouter.d.ts +4 -1
- package/dist/app/lib/routing/components/BrowserRouter.js +68 -11
- package/dist/app/lib/routing/components/ClientOnly.js +1 -1
- package/dist/app/lib/routing/components/Link.d.ts +1 -0
- package/dist/app/lib/routing/components/Link.js +9 -10
- package/dist/app/lib/routing/components/RouteRenderer.d.ts +1 -1
- package/dist/app/lib/routing/components/RouteRenderer.js +7 -6
- package/dist/app/lib/routing/components/SSRRouter.d.ts +2 -2
- package/dist/app/lib/routing/components/SSRRouter.js +5 -6
- package/dist/app/lib/routing/components/ScrollRestoration.js +1 -1
- package/dist/app/lib/routing/context.d.ts +2 -2
- package/dist/app/lib/routing/context.js +6 -96
- package/dist/app/lib/routing/hooks/useRestorableState.js +2 -1
- package/dist/app/lib/routing/hooks/useRoute.d.ts +16 -1
- package/dist/app/lib/routing/hooks/useRoute.js +22 -1
- package/dist/app/lib/routing/hooks/useRouteMeta.d.ts +5 -0
- package/dist/app/lib/routing/hooks/useRouteMeta.js +9 -0
- package/dist/app/lib/routing/hooks/useRouteTransition.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouteTransition.js +1 -1
- package/dist/app/lib/routing/hooks/useRouter.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouter.js +1 -1
- package/dist/app/lib/routing/hooks/useRouterEvents.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouterEvents.js +1 -1
- package/dist/app/lib/routing/hooks/useRouterState.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouterState.js +1 -1
- package/dist/app/lib/routing/hooks/useSearchParams.js +2 -2
- package/dist/app/lib/routing/index.d.ts +14 -13
- package/dist/app/lib/routing/index.js +14 -13
- package/dist/app/lib/routing/loader.d.ts +2 -2
- package/dist/app/lib/routing/loader.js +7 -5
- package/dist/app/lib/routing/types.d.ts +20 -8
- package/dist/app/lib/routing/utils.d.ts +3 -1
- package/dist/app/lib/routing/utils.js +11 -0
- package/dist/app/lib/views/index.d.ts +1 -1
- package/dist/app/lib/views/index.js +1 -1
- package/dist/app/server/defineRouter.d.ts +2 -0
- package/dist/app/server/defineRouter.js +4 -0
- package/dist/app/server/index.d.ts +4 -0
- package/dist/app/server/index.js +4 -0
- package/dist/app/server/proxy-wp-admin.d.ts +3 -0
- package/dist/app/server/proxy-wp-admin.js +105 -0
- package/dist/app/server/render-ssr-page.d.ts +3 -0
- package/dist/app/server/render-ssr-page.js +29 -0
- package/dist/app/server/server-context.d.ts +43 -0
- package/dist/app/server/server-context.js +140 -0
- package/dist/app/server/utils/headers.d.ts +1 -0
- package/dist/app/server/utils/headers.js +17 -0
- package/dist/app/server/utils/replace-host.d.ts +6 -4
- package/dist/app/server/utils/replace-host.js +58 -11
- package/dist/node/cli/cli-worker.d.ts +1 -1
- package/dist/node/cli/cli-worker.js +7 -2
- package/dist/node/cli/cli.js +84 -12
- package/dist/node/cli/display/CLIApp.d.ts +1 -1
- package/dist/node/cli/display/CLIApp.js +3 -6
- package/dist/node/cli/display/components/LogEntries.d.ts +1 -1
- package/dist/node/cli/display/hooks/useStatefulLog.d.ts +1 -1
- package/dist/node/cli/display/tools/CreateBlock.d.ts +1 -1
- package/dist/node/cli/display/tools/cli-tools.d.ts +1 -11
- package/dist/node/cli/display/tools/cli-tools.js +9 -9
- package/dist/node/cli/display/util/colors.d.ts +2 -2
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.js +1 -1
- package/dist/node/compiler/build-vinxi.d.ts +8 -0
- package/dist/node/compiler/build-vinxi.js +37 -0
- package/dist/node/compiler/bundler.admin.d.ts +2 -2
- package/dist/node/compiler/bundler.admin.js +3 -4
- package/dist/node/compiler/bundler.frontend.d.ts +1 -1
- package/dist/node/compiler/bundler.frontend.js +3 -4
- package/dist/node/compiler/{serverless.dev.d.ts → dev-server.d.ts} +7 -5
- package/dist/node/compiler/dev-server.js +97 -0
- package/dist/node/compiler/get-vite-config.d.ts +19 -0
- package/dist/node/compiler/get-vite-config.js +200 -0
- package/dist/node/compiler/vinxi-app.d.ts +19 -0
- package/dist/node/compiler/vinxi-app.js +153 -0
- package/dist/node/compiler/vinxi-codegen.d.ts +12 -0
- package/dist/node/compiler/vinxi-codegen.js +458 -0
- package/dist/node/graphql/graphql-codegen.d.ts +1 -1
- package/dist/node/graphql/graphql-codegen.js +7 -4
- package/dist/node/graphql/graphql-schema-loader.js +15 -18
- package/dist/node/project/config.js +1 -1
- package/dist/node/project/env.d.ts +1 -1
- package/dist/node/project/env.js +1 -1
- package/dist/node/project/manifest/block-manifest.js +2 -2
- package/dist/node/project/manifest/manifest.d.ts +1 -1
- package/dist/node/project/manifest/manifest.js +1 -1
- package/dist/node/project/manifest/view-manifest.js +2 -2
- package/dist/node/project/project.d.ts +3 -2
- package/dist/node/project/project.js +18 -20
- package/dist/node/project/wp-info.js +3 -2
- package/dist/node/types/view-type.js +3 -4
- package/dist/node/utils/fs-codegen.d.ts +40 -0
- package/dist/node/utils/fs-codegen.js +97 -0
- package/dist/node/utils/fs.js +2 -0
- package/dist/node/utils/{selfSignedCert.js → self-signed-cert.js} +1 -1
- package/dist/node/utils/{statefulLog.js → stateful-log.js} +1 -1
- package/package.json +30 -32
- package/types.app.d.ts +2 -2
- package/types.app.internal.d.ts +2 -2
- package/types.node.d.ts +3 -3
- package/dist/app/entry/Root.d.ts +0 -1
- package/dist/app/entry/main.admin.d.ts +0 -3
- package/dist/app/entry/main.frontend.spa.d.ts +0 -3
- package/dist/app/entry/main.frontend.spa.js +0 -13
- package/dist/app/entry/main.frontend.ssr.d.ts +0 -21
- package/dist/app/entry/main.frontend.ssr.js +0 -79
- package/dist/app/entry/main.serverless.dev.d.ts +0 -4
- package/dist/app/entry/main.serverless.dev.js +0 -21
- package/dist/app/lib/hooks/usePageLoad.d.ts +0 -6
- package/dist/app/lib/hooks/usePageLoad.js +0 -5
- package/dist/app/server/create-api-builtin-hono.d.ts +0 -8
- package/dist/app/server/create-api-builtin-hono.js +0 -80
- package/dist/app/server/create-ssr-hono.d.ts +0 -18
- package/dist/app/server/create-ssr-hono.js +0 -104
- package/dist/app/server/utils/index.html.d.ts +0 -2
- package/dist/app/server/utils/index.html.js +0 -14
- package/dist/node/compiler/index.html.d.ts +0 -2
- package/dist/node/compiler/index.html.js +0 -15
- package/dist/node/compiler/serverless.dev.js +0 -215
- package/dist/node/compiler/vite/get-vite-config.d.ts +0 -13
- package/dist/node/compiler/vite/get-vite-config.js +0 -315
- package/dist/node/compiler/vite/plugin-admin.d.ts +0 -4
- package/dist/node/compiler/vite/plugin-admin.js +0 -67
- package/dist/node/compiler/vite/plugin-blocks.d.ts +0 -4
- package/dist/node/compiler/vite/plugin-blocks.js +0 -73
- package/dist/node/compiler/vite/plugin-entry.d.ts +0 -6
- package/dist/node/compiler/vite/plugin-entry.js +0 -16
- package/dist/node/compiler/vite/plugin-resolved-tailwind.d.ts +0 -4
- package/dist/node/compiler/vite/plugin-resolved-tailwind.js +0 -29
- package/dist/node/compiler/vite/plugin-theme.d.ts +0 -4
- package/dist/node/compiler/vite/plugin-theme.js +0 -40
- package/dist/node/compiler/vite/plugin-views.d.ts +0 -4
- package/dist/node/compiler/vite/plugin-views.js +0 -51
- package/dist/node/utils/console.d.ts +0 -21
- package/dist/node/utils/console.js +0 -28
- package/dist/node/utils/unsafe-fetch.d.ts +0 -2
- package/dist/node/utils/unsafe-fetch.js +0 -19
- package/tsup.config.ts +0 -40
- package/types.manifests.d.ts +0 -22
- /package/dist/node/utils/{formatZodError.d.ts → format-zod-error.d.ts} +0 -0
- /package/dist/node/utils/{formatZodError.js → format-zod-error.js} +0 -0
- /package/dist/node/utils/{getRepoInfo.d.ts → get-repo-info.d.ts} +0 -0
- /package/dist/node/utils/{getRepoInfo.js → get-repo-info.js} +0 -0
- /package/dist/node/utils/{highlightCode.d.ts → highlight-code.d.ts} +0 -0
- /package/dist/node/utils/{highlightCode.js → highlight-code.js} +0 -0
- /package/dist/node/utils/{isDeploying.d.ts → is-deploying.d.ts} +0 -0
- /package/dist/node/utils/{isDeploying.js → is-deploying.js} +0 -0
- /package/dist/node/utils/{selfSignedCert.d.ts → self-signed-cert.d.ts} +0 -0
- /package/dist/node/utils/{statefulLog.d.ts → stateful-log.d.ts} +0 -0
- /package/dist/node/utils/{export-extractor.d.ts → ts-export-extractor.d.ts} +0 -0
- /package/dist/node/utils/{export-extractor.js → ts-export-extractor.js} +0 -0
- /package/dist/node/utils/{watchFileTree.d.ts → watch-file-tree.d.ts} +0 -0
- /package/dist/node/utils/{watchFileTree.js → watch-file-tree.js} +0 -0
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useRef, useState, useTransition } from "react";
|
|
3
|
-
import { isRelative, parseURL, resolveURL } from "ufo";
|
|
4
|
-
import { RouterContext, RouterStateContext } from "../context";
|
|
5
|
-
import { RouteLoader } from "../loader";
|
|
6
|
-
import { getLinkHandlerMode, normalizeRoute, parseQuery, stringifyRouteLink } from "../utils";
|
|
7
|
-
import { AppRenderer } from "./RouteRenderer";
|
|
3
|
+
import { isEqual, isRelative, parseURL, resolveURL } from "ufo";
|
|
4
|
+
import { RouterContext, RouterStateContext } from "../context.js";
|
|
5
|
+
import { RouteLoader } from "../loader.js";
|
|
6
|
+
import { getLinkHandlerMode, getRouteMeta, isSamePathname, normalizeRoute, parseQuery, stringifyRouteLink, } from "../utils.js";
|
|
7
|
+
import { AppRenderer } from "./RouteRenderer.js";
|
|
8
|
+
import { $routeMetaStore } from "../hooks/useRouteMeta.js";
|
|
9
|
+
// Create a global RouteLoader instance
|
|
8
10
|
const loader = new RouteLoader();
|
|
11
|
+
// Create a unique ID for each history entry
|
|
12
|
+
let historyStamp = String(new Date().getTime());
|
|
13
|
+
let historyIndex = 0;
|
|
14
|
+
function getHistoryId() {
|
|
15
|
+
return historyStamp + historyIndex++;
|
|
16
|
+
}
|
|
17
|
+
// Set up the initial route data
|
|
9
18
|
let initialRoute;
|
|
10
19
|
let initialRouteHydrated = false;
|
|
11
20
|
if (env.client && !env.admin) {
|
|
@@ -23,7 +32,10 @@ if (env.client && !env.admin) {
|
|
|
23
32
|
search: "",
|
|
24
33
|
query: {},
|
|
25
34
|
view: initialData.view,
|
|
35
|
+
meta: getRouteMeta(initialData),
|
|
26
36
|
});
|
|
37
|
+
history.replaceState(historyStateForRoute(initialRoute), "", document.location.href);
|
|
38
|
+
$routeMetaStore.data = getRouteMeta(initialData);
|
|
27
39
|
}
|
|
28
40
|
function parseHrefPath(url) {
|
|
29
41
|
if (isRelative(url)) {
|
|
@@ -54,14 +66,9 @@ function historyStateForRoute(route) {
|
|
|
54
66
|
state: route.returnState,
|
|
55
67
|
};
|
|
56
68
|
}
|
|
57
|
-
let index = 0;
|
|
58
|
-
function getHistoryId() {
|
|
59
|
-
return String(index++);
|
|
60
|
-
}
|
|
61
69
|
let lastRouterState = null;
|
|
62
70
|
export function BrowserRouter(props) {
|
|
63
71
|
const pendingRoute = useRef(null);
|
|
64
|
-
// const [activeRoute, setActiveRoute] = useState<RouteState>(initialRoute)
|
|
65
72
|
const [transitioning, startTransition] = useTransition();
|
|
66
73
|
const [routerState, setRouterState] = useState(() => ({
|
|
67
74
|
activeRoute: initialRoute,
|
|
@@ -116,6 +123,7 @@ export function BrowserRouter(props) {
|
|
|
116
123
|
}
|
|
117
124
|
internals.poppedState = (href, data) => {
|
|
118
125
|
const stack = state.history;
|
|
126
|
+
console.log("Popped state", stack);
|
|
119
127
|
// Is the route in our history stack? (going back)
|
|
120
128
|
const index = stack.findIndex((item) => item.id === data.id);
|
|
121
129
|
if (index >= 0) {
|
|
@@ -201,6 +209,7 @@ export function BrowserRouter(props) {
|
|
|
201
209
|
props: data.viewData?.data ?? {},
|
|
202
210
|
component: lazyComponent,
|
|
203
211
|
returnState: args.restoreState ?? {},
|
|
212
|
+
meta: getRouteMeta(data),
|
|
204
213
|
});
|
|
205
214
|
setState({
|
|
206
215
|
pendingRoute: route,
|
|
@@ -229,6 +238,7 @@ export function BrowserRouter(props) {
|
|
|
229
238
|
lastRoute: currentRoute,
|
|
230
239
|
link,
|
|
231
240
|
});
|
|
241
|
+
$routeMetaStore.data = route.meta;
|
|
232
242
|
};
|
|
233
243
|
startTransition(() => {
|
|
234
244
|
pendingRoute.current = route;
|
|
@@ -247,6 +257,9 @@ export function BrowserRouter(props) {
|
|
|
247
257
|
goingBack: false,
|
|
248
258
|
});
|
|
249
259
|
},
|
|
260
|
+
getState() {
|
|
261
|
+
return state;
|
|
262
|
+
},
|
|
250
263
|
replaceHash(hash) {
|
|
251
264
|
replaceRoute({
|
|
252
265
|
...getActiveRoute(),
|
|
@@ -297,7 +310,7 @@ export function BrowserRouter(props) {
|
|
|
297
310
|
subscribers.delete(fn);
|
|
298
311
|
};
|
|
299
312
|
},
|
|
300
|
-
handleClickEvent(e, originalHref) {
|
|
313
|
+
handleClickEvent(e, originalHref, preferBack) {
|
|
301
314
|
const { mode, href } = getLinkHandlerMode(e, originalHref);
|
|
302
315
|
if (mode === "ignore") {
|
|
303
316
|
e.preventDefault();
|
|
@@ -308,10 +321,53 @@ export function BrowserRouter(props) {
|
|
|
308
321
|
}
|
|
309
322
|
else if (mode === "navigate" && href) {
|
|
310
323
|
e.preventDefault();
|
|
324
|
+
if (preferBack) {
|
|
325
|
+
const lastState = state.history.length > 1 && state.history[state.history.length - 2];
|
|
326
|
+
if (lastState) {
|
|
327
|
+
const doesMatch = preferBack === "exact" ? isEqual(href, lastState.uri) : isSamePathname(href, lastState.uri);
|
|
328
|
+
if (doesMatch) {
|
|
329
|
+
history.back();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
311
334
|
api.navigate(href);
|
|
312
335
|
}
|
|
313
336
|
},
|
|
314
337
|
emitEvent,
|
|
338
|
+
restoreRoute(route) {
|
|
339
|
+
const stack = state.history;
|
|
340
|
+
// Is the route in our history stack? (going back)
|
|
341
|
+
const index = stack.findIndex((item) => item.id === route.id);
|
|
342
|
+
if (index >= 0) {
|
|
343
|
+
return doRouteTransition({
|
|
344
|
+
url: route.uri,
|
|
345
|
+
route,
|
|
346
|
+
goingBack: true,
|
|
347
|
+
history: stack.slice(0, index),
|
|
348
|
+
restoreState: route.returnState,
|
|
349
|
+
shouldPush: false,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
// Is the route in our history _cache_? (probably going forward)
|
|
353
|
+
if (historyCache.has(route.id)) {
|
|
354
|
+
return doRouteTransition({
|
|
355
|
+
url: route.uri,
|
|
356
|
+
route,
|
|
357
|
+
goingBack: false,
|
|
358
|
+
history: stack,
|
|
359
|
+
restoreState: route.returnState,
|
|
360
|
+
shouldPush: false,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
return doRouteTransition({
|
|
364
|
+
url: route.uri,
|
|
365
|
+
goingBack: false,
|
|
366
|
+
history: stack,
|
|
367
|
+
restoreState: route.returnState,
|
|
368
|
+
shouldPush: false,
|
|
369
|
+
});
|
|
370
|
+
},
|
|
315
371
|
};
|
|
316
372
|
return {
|
|
317
373
|
api,
|
|
@@ -340,6 +396,7 @@ export function BrowserRouter(props) {
|
|
|
340
396
|
// Handle popState
|
|
341
397
|
// const router = useRouterStore.getState()
|
|
342
398
|
const onPopState = (e) => {
|
|
399
|
+
console.log("Popped", e.state);
|
|
343
400
|
internals.poppedState?.(document.location.href, e.state ?? {});
|
|
344
401
|
};
|
|
345
402
|
window.addEventListener("popstate", onPopState);
|
|
@@ -3,6 +3,7 @@ type Props<T extends ElementType = "a"> = NoInfer<Omit<ComponentPropsWithRef<T>,
|
|
|
3
3
|
href?: string | null;
|
|
4
4
|
target?: string | null;
|
|
5
5
|
as?: T;
|
|
6
|
+
preferBack?: boolean | "exact";
|
|
6
7
|
};
|
|
7
8
|
export declare const Link: <T extends ElementType = "a">(props: Props<T>) => ReactElement;
|
|
8
9
|
/**
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useMemo } from "react";
|
|
3
3
|
import { parseURL, resolveURL, withoutTrailingSlash } from "ufo";
|
|
4
|
-
import { useIsSSR } from "../hooks/useIsSSR";
|
|
5
|
-
import { useRouter } from "../hooks/useRouter";
|
|
6
|
-
import { isSameOrigin } from "../utils";
|
|
7
|
-
import { useRoute } from "../hooks/useRoute";
|
|
8
|
-
import { useRouterState } from "../hooks/useRouterState";
|
|
9
|
-
export const Link = forwardRef((props, ref) => {
|
|
4
|
+
import { useIsSSR } from "../hooks/useIsSSR.js";
|
|
5
|
+
import { useRouter } from "../hooks/useRouter.js";
|
|
6
|
+
import { isSameOrigin } from "../utils.js";
|
|
7
|
+
import { useRoute } from "../hooks/useRoute.js";
|
|
8
|
+
import { useRouterState } from "../hooks/useRouterState.js";
|
|
9
|
+
export const Link = forwardRef(({ preferBack, ...props }, ref) => {
|
|
10
10
|
const Comp = props.as || "a";
|
|
11
11
|
if (env.admin) {
|
|
12
12
|
return (_jsx(Comp, { ref: ref, ...props, href: props.href ?? undefined, onClick: (e) => {
|
|
@@ -15,17 +15,16 @@ export const Link = forwardRef((props, ref) => {
|
|
|
15
15
|
} }));
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
|
-
const
|
|
19
|
-
const handleClickEvent = useRouter((r) => r.handleClickEvent);
|
|
18
|
+
const router = useRouter();
|
|
20
19
|
const state = useLinkState(props.href ?? "");
|
|
21
20
|
return (_jsx(Comp, { ref: ref, "data-active": state.active ?? undefined, "data-child-active": state.childActive ?? undefined, "data-pending": state.pending ?? undefined, ...props, href: props.href ?? undefined, onMouseEnter: (e) => {
|
|
22
21
|
if (props.onMouseEnter) {
|
|
23
22
|
props.onMouseEnter(e);
|
|
24
23
|
}
|
|
25
|
-
preload(props.href);
|
|
24
|
+
router.preload(props.href);
|
|
26
25
|
}, onClick: (e) => {
|
|
27
26
|
props.onClick?.(e);
|
|
28
|
-
handleClickEvent(e, props.href ?? undefined);
|
|
27
|
+
router.handleClickEvent(e, props.href ?? undefined, preferBack);
|
|
29
28
|
} }));
|
|
30
29
|
}
|
|
31
30
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RouteState } from "../types";
|
|
1
|
+
import { RouteState } from "../types.js";
|
|
2
2
|
export declare const AppRenderer: import("react").MemoExoticComponent<() => import("react/jsx-runtime").JSX.Element>;
|
|
3
3
|
export declare function MainRoute(): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
export declare function RouteDisplay(props: {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { memo,
|
|
3
|
-
import { RouteItemContext } from "../context";
|
|
4
|
-
import { useRouter } from "../hooks/useRouter";
|
|
5
|
-
import { useRouterState } from "../hooks/useRouterState";
|
|
2
|
+
import { memo, useMemo } from "react";
|
|
3
|
+
import { RouteItemContext } from "../context.js";
|
|
4
|
+
import { useRouter } from "../hooks/useRouter.js";
|
|
5
|
+
import { useRouterState } from "../hooks/useRouterState.js";
|
|
6
|
+
import { ErrorBoundaryFrontend } from "../../blocks/ErrorBoundaryFrontend.js";
|
|
6
7
|
export const AppRenderer = memo(() => {
|
|
7
8
|
const { appData, appComponent: AppComponent } = useRouter().loader;
|
|
8
9
|
const { activeRoute } = useRouterState();
|
|
9
10
|
const app = useMemo(() => {
|
|
10
11
|
return (_jsx(AppComponent, { ...appData, children: _jsx(MainRoute, {}) }));
|
|
11
12
|
}, [AppComponent, appData]);
|
|
12
|
-
return
|
|
13
|
+
return _jsx(RouteItemContext.Provider, { value: activeRoute, children: app });
|
|
13
14
|
});
|
|
14
15
|
export function MainRoute() {
|
|
15
16
|
const activeRoute = useRouterState((s) => s.activeRoute);
|
|
@@ -22,7 +23,7 @@ export function RouteDisplay(props) {
|
|
|
22
23
|
}
|
|
23
24
|
return useMemo(() => {
|
|
24
25
|
let child = !!Component && _jsx(Component, { ...props.route.props });
|
|
25
|
-
return _jsx(RouteItemContext.Provider, { value: props.route, children: child });
|
|
26
|
+
return (_jsx(ErrorBoundaryFrontend, { children: _jsx(RouteItemContext.Provider, { value: props.route, children: child }) }));
|
|
26
27
|
}, [Component, props.route, props.route]);
|
|
27
28
|
}
|
|
28
29
|
RouteDisplay.displayName = "RouteDisplay";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
|
-
import { RouteLoader } from "../loader";
|
|
3
|
-
import { RouteState } from "../types";
|
|
2
|
+
import { RouteLoader } from "../loader.js";
|
|
3
|
+
import { RouteState } from "../types.js";
|
|
4
4
|
type Props = PropsWithChildren<{
|
|
5
5
|
route: RouteState;
|
|
6
6
|
loader: RouteLoader;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { AppRenderer } from "./RouteRenderer";
|
|
2
|
+
import { RouterContext, RouterStateContext } from "../context.js";
|
|
3
|
+
import { useRouter } from "../hooks/useRouter.js";
|
|
4
|
+
import { useRouterState } from "../hooks/useRouterState.js";
|
|
5
|
+
import { AppRenderer } from "./RouteRenderer.js";
|
|
7
6
|
export function SSRRouter(props) {
|
|
8
7
|
const router = useRouter();
|
|
9
8
|
const routerState = useRouterState();
|
|
10
9
|
router.loader = props.loader;
|
|
11
10
|
routerState.history = [props.route];
|
|
12
11
|
routerState.activeRoute = props.route;
|
|
13
|
-
return (_jsx(
|
|
12
|
+
return (_jsx(RouterContext.Provider, { value: router, children: _jsx(RouterStateContext.Provider, { value: routerState, children: _jsx(AppRenderer, {}) }) }));
|
|
14
13
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context } from "react";
|
|
2
|
-
import { RouterAPI, RouterAPIState } from "./types";
|
|
2
|
+
import { RouterAPI, RouterAPIState } from "./types.js";
|
|
3
3
|
export declare const RouterContext: Context<RouterAPI>;
|
|
4
4
|
export declare const RouterStateContext: Context<RouterAPIState>;
|
|
5
|
-
export declare const RouteItemContext: Context<import("./types").TypedRouteState<"_unknown", {}>>;
|
|
5
|
+
export declare const RouteItemContext: Context<import("./types.js").TypedRouteState<"_unknown", {}>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext } from "react";
|
|
2
|
-
import { RouteLoader } from "./loader";
|
|
2
|
+
import { RouteLoader } from "./loader.js";
|
|
3
3
|
const NOOP_ROUTE = {
|
|
4
4
|
component: () => null,
|
|
5
5
|
id: "initial",
|
|
@@ -12,6 +12,7 @@ const NOOP_ROUTE = {
|
|
|
12
12
|
search: "",
|
|
13
13
|
query: {},
|
|
14
14
|
returnState: undefined,
|
|
15
|
+
meta: {},
|
|
15
16
|
};
|
|
16
17
|
export const RouterContext = createContext({
|
|
17
18
|
loader: new RouteLoader(),
|
|
@@ -25,6 +26,10 @@ export const RouterContext = createContext({
|
|
|
25
26
|
replaceQuery(query) { },
|
|
26
27
|
handleClickEvent(e, originalHref) { },
|
|
27
28
|
emitEvent(event) { },
|
|
29
|
+
getState() {
|
|
30
|
+
return null;
|
|
31
|
+
},
|
|
32
|
+
restoreRoute(route) { },
|
|
28
33
|
});
|
|
29
34
|
export const RouterStateContext = createContext({
|
|
30
35
|
history: [NOOP_ROUTE],
|
|
@@ -32,98 +37,3 @@ export const RouterStateContext = createContext({
|
|
|
32
37
|
blockers: [],
|
|
33
38
|
});
|
|
34
39
|
export const RouteItemContext = createContext(NOOP_ROUTE);
|
|
35
|
-
// type StoreHook<State> = <Slice = State>(
|
|
36
|
-
// selector?: (state: State) => Slice,
|
|
37
|
-
// areEqual?: (a: Slice, b: Slice) => boolean,
|
|
38
|
-
// ) => Slice
|
|
39
|
-
// type Store<T> = {
|
|
40
|
-
// subscribe(sub: (value: T) => void): () => void
|
|
41
|
-
// value: T
|
|
42
|
-
// update(next: T): void
|
|
43
|
-
// }
|
|
44
|
-
// function createStore<T>(initial: T): Store<T> {
|
|
45
|
-
// let value = initial
|
|
46
|
-
// const subscribers = new Set<(value: T) => void>()
|
|
47
|
-
// return {
|
|
48
|
-
// subscribe(sub: (value: T) => void) {
|
|
49
|
-
// subscribers.add(sub)
|
|
50
|
-
// return () => {
|
|
51
|
-
// subscribers.delete(sub)
|
|
52
|
-
// }
|
|
53
|
-
// },
|
|
54
|
-
// get value() {
|
|
55
|
-
// return value
|
|
56
|
-
// },
|
|
57
|
-
// update(nextValue: T) {
|
|
58
|
-
// value = nextValue
|
|
59
|
-
// if (subscribers.size) {
|
|
60
|
-
// console.log("UPDATE", value)
|
|
61
|
-
// startTransition(() => {
|
|
62
|
-
// for (let sub of subscribers) {
|
|
63
|
-
// sub(value)
|
|
64
|
-
// }
|
|
65
|
-
// })
|
|
66
|
-
// }
|
|
67
|
-
// },
|
|
68
|
-
// }
|
|
69
|
-
// }
|
|
70
|
-
// export function createStoreHook<T>(store: Store<T>): StoreHook<T> {
|
|
71
|
-
// const hook = (selector: any) => {
|
|
72
|
-
// const get = () => (selector ? selector(store.value) : store.value)
|
|
73
|
-
// return useSyncExternalStore(store.subscribe, get, get)
|
|
74
|
-
// }
|
|
75
|
-
// return hook as StoreHook<T>
|
|
76
|
-
// }
|
|
77
|
-
// export function createStoreContextHook<T>(ctx: Context<Store<T>>): StoreHook<T> {
|
|
78
|
-
// const hook = (selector: any) => {
|
|
79
|
-
// const store = useContext(ctx)
|
|
80
|
-
// const get = () => (selector ? selector(store.value) : store.value)
|
|
81
|
-
// return useSyncExternalStore(store.subscribe, get, get)
|
|
82
|
-
// }
|
|
83
|
-
// return hook as StoreHook<T>
|
|
84
|
-
// }
|
|
85
|
-
// export const RouterContext = createContext<Store<RouterAPI>>(null!)
|
|
86
|
-
// export const RouterStateContext = createContext<Store<RouterAPIState>>(null!)
|
|
87
|
-
// export const RouteContext = createContext<Store<RouteState>>(null!)
|
|
88
|
-
// const NOOP_ROUTE: RouteState = {
|
|
89
|
-
// component: () => null,
|
|
90
|
-
// id: "initial",
|
|
91
|
-
// hash: "",
|
|
92
|
-
// key: "initial",
|
|
93
|
-
// pathname: "",
|
|
94
|
-
// props: {},
|
|
95
|
-
// uri: "",
|
|
96
|
-
// view: "_unknown",
|
|
97
|
-
// search: "",
|
|
98
|
-
// query: {},
|
|
99
|
-
// returnState: undefined,
|
|
100
|
-
// }
|
|
101
|
-
// export const createRouteItemStore = (initial?: RouteState) => {
|
|
102
|
-
// return createStore<RouteState>(initial ?? NOOP_ROUTE)
|
|
103
|
-
// }
|
|
104
|
-
// export function createRouterAPIStore(initial?: RouterAPI) {
|
|
105
|
-
// return createStore<RouterAPI>(
|
|
106
|
-
// initial ?? {
|
|
107
|
-
// loader: new RouteLoader(),
|
|
108
|
-
// async navigate(url) {},
|
|
109
|
-
// async prefetch(url) {},
|
|
110
|
-
// async preload(url) {},
|
|
111
|
-
// subscribe(fn) {
|
|
112
|
-
// return () => {}
|
|
113
|
-
// },
|
|
114
|
-
// replaceHash(hash) {},
|
|
115
|
-
// replaceQuery(query) {},
|
|
116
|
-
// handleClickEvent(e, originalHref) {},
|
|
117
|
-
// emitEvent(event) {},
|
|
118
|
-
// },
|
|
119
|
-
// )
|
|
120
|
-
// }
|
|
121
|
-
// export function createRouterStateStore(initial?: RouterAPIState) {
|
|
122
|
-
// return createStore<RouterAPIState>(
|
|
123
|
-
// initial ?? {
|
|
124
|
-
// history: [],
|
|
125
|
-
// activeRoute: NOOP_ROUTE,
|
|
126
|
-
// blockers: [],
|
|
127
|
-
// },
|
|
128
|
-
// )
|
|
129
|
-
// }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { useRouterEvents } from "./useRouterEvents.js";
|
|
3
|
+
import { useRoute } from "./useRoute.js";
|
|
3
4
|
/**
|
|
4
5
|
* Works exactly like useState, but allows back and forward navigation to restore the previous state.
|
|
5
6
|
* You must pass a unique ID as an additional first parameter to ensure the state is restored correctly.
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
import { RouteState } from "../types";
|
|
1
|
+
import type { RouteState } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the current route object.
|
|
4
|
+
*
|
|
5
|
+
* In most circumstances, this will be the active top-level route.
|
|
6
|
+
*
|
|
7
|
+
* In cases where manual rendering of routes is taking place, such as during page transitions or in some modal cases.
|
|
8
|
+
*
|
|
9
|
+
* @returns The current route
|
|
10
|
+
*/
|
|
2
11
|
export declare function useRoute(): RouteState;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the current route, if it matches the specified view, otherwise null.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useViewRoute<V extends keyof ViewProps>(view: V): Extract<RouteState, {
|
|
16
|
+
view: V;
|
|
17
|
+
}> | null;
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
|
-
import { RouteItemContext } from "../context";
|
|
2
|
+
import { RouteItemContext } from "../context.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the current route object.
|
|
5
|
+
*
|
|
6
|
+
* In most circumstances, this will be the active top-level route.
|
|
7
|
+
*
|
|
8
|
+
* In cases where manual rendering of routes is taking place, such as during page transitions or in some modal cases.
|
|
9
|
+
*
|
|
10
|
+
* @returns The current route
|
|
11
|
+
*/
|
|
3
12
|
export function useRoute() {
|
|
4
13
|
return useContext(RouteItemContext);
|
|
5
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns the current route, if it matches the specified view, otherwise null.
|
|
17
|
+
*/
|
|
18
|
+
export function useViewRoute(view) {
|
|
19
|
+
const route = useContext(RouteItemContext);
|
|
20
|
+
if (route.view === view) {
|
|
21
|
+
return route;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RouteState } from "../types";
|
|
1
|
+
import type { RouteState } from "../types.js";
|
|
2
2
|
type TransitionFunction = (currentRoute: RouteState, nextRoute: RouteState) => void | Promise<any | void>;
|
|
3
3
|
export declare function useRouteTransition(func: TransitionFunction): void;
|
|
4
4
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RouterAPI } from "../types";
|
|
1
|
+
import { RouterAPI } from "../types.js";
|
|
2
2
|
export declare function useRouter<T = RouterAPI>(selector?: (r: RouterAPI) => T): T;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { RouterEvent } from "../types";
|
|
1
|
+
import type { RouterEvent } from "../types.js";
|
|
2
2
|
export declare function useRouterEvents(handler: (event: RouterEvent) => void): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RouterAPIState } from "../types";
|
|
1
|
+
import { RouterAPIState } from "../types.js";
|
|
2
2
|
export declare function useRouterState<T = RouterAPIState>(selector?: (state: RouterAPIState) => T): T;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import { useRoute } from "./useRoute";
|
|
3
|
-
import { useRouter } from "./useRouter";
|
|
2
|
+
import { useRoute } from "./useRoute.js";
|
|
3
|
+
import { useRouter } from "./useRouter.js";
|
|
4
4
|
export function useSearchParams(defaultValue) {
|
|
5
5
|
const route = useRoute();
|
|
6
6
|
const replaceQuery = useRouter((r) => r.replaceQuery);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
export * from "./types";
|
|
2
|
-
export * from "./components/Link";
|
|
3
|
-
export * from "./components/ScrollRestoration";
|
|
4
|
-
export * from "./components/RouteRenderer";
|
|
5
|
-
export * from "./components/ClientOnly";
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./hooks/
|
|
8
|
-
export * from "./hooks/
|
|
9
|
-
export * from "./hooks/
|
|
10
|
-
export * from "./hooks/
|
|
11
|
-
export * from "./hooks/
|
|
12
|
-
export * from "./hooks/
|
|
13
|
-
export * from "./hooks/
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./components/Link.js";
|
|
3
|
+
export * from "./components/ScrollRestoration.js";
|
|
4
|
+
export * from "./components/RouteRenderer.js";
|
|
5
|
+
export * from "./components/ClientOnly.js";
|
|
6
|
+
export * from "./components/BackButton.js";
|
|
7
|
+
export * from "./hooks/useRoute.js";
|
|
8
|
+
export * from "./hooks/useRouteTransition.js";
|
|
9
|
+
export * from "./hooks/useRouter.js";
|
|
10
|
+
export * from "./hooks/useRouterEvents.js";
|
|
11
|
+
export * from "./hooks/useRouterState.js";
|
|
12
|
+
export * from "./hooks/useRestorableState.js";
|
|
13
|
+
export * from "./hooks/useIsSSR.js";
|
|
14
|
+
export * from "./hooks/useSearchParams.js";
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
export * from "./types";
|
|
2
|
-
export * from "./components/Link";
|
|
3
|
-
export * from "./components/ScrollRestoration";
|
|
4
|
-
export * from "./components/RouteRenderer";
|
|
5
|
-
export * from "./components/ClientOnly";
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./hooks/
|
|
8
|
-
export * from "./hooks/
|
|
9
|
-
export * from "./hooks/
|
|
10
|
-
export * from "./hooks/
|
|
11
|
-
export * from "./hooks/
|
|
12
|
-
export * from "./hooks/
|
|
13
|
-
export * from "./hooks/
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./components/Link.js";
|
|
3
|
+
export * from "./components/ScrollRestoration.js";
|
|
4
|
+
export * from "./components/RouteRenderer.js";
|
|
5
|
+
export * from "./components/ClientOnly.js";
|
|
6
|
+
export * from "./components/BackButton.js";
|
|
7
|
+
export * from "./hooks/useRoute.js";
|
|
8
|
+
export * from "./hooks/useRouteTransition.js";
|
|
9
|
+
export * from "./hooks/useRouter.js";
|
|
10
|
+
export * from "./hooks/useRouterEvents.js";
|
|
11
|
+
export * from "./hooks/useRouterState.js";
|
|
12
|
+
export * from "./hooks/useRestorableState.js";
|
|
13
|
+
export * from "./hooks/useIsSSR.js";
|
|
14
|
+
export * from "./hooks/useSearchParams.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FunctionComponent, PropsWithChildren } from "react";
|
|
2
|
-
import { DynamicComponent } from "../dynamic/dynamic";
|
|
3
|
-
import { RouteData } from "./types";
|
|
2
|
+
import { DynamicComponent } from "../dynamic/dynamic.js";
|
|
3
|
+
import { RouteData } from "./types.js";
|
|
4
4
|
export type RouteCacheEntry = {
|
|
5
5
|
data: RouteData;
|
|
6
6
|
component: FunctionComponent;
|