create-vitnode-app 2.0.0-canary.1 → 2.0.0-canary.10
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/README.md +9 -2
- package/copy-of-vitnode-app/README.md +22 -0
- package/copy-of-vitnode-app/api/src/vitnode.api.config.ts +10 -11
- package/copy-of-vitnode-app/api-single-app/src/routes/api/$.ts +4 -26
- package/copy-of-vitnode-app/api-single-app/src/server/api-bridge.ts +1 -12
- package/copy-of-vitnode-app/api-single-app/src/server/vitnode-api.server.ts +13 -13
- package/copy-of-vitnode-app/api-single-app/src/vitnode.api.config.ts +3 -12
- package/copy-of-vitnode-app/docker/docker-compose.yml +6 -4
- package/copy-of-vitnode-app/monorepo/apps/api/.env.example +1 -1
- package/copy-of-vitnode-app/monorepo/apps/web/.env.example +1 -12
- package/copy-of-vitnode-app/monorepo/turbo.json +2 -2
- package/copy-of-vitnode-app/root/.env.example +1 -8
- package/copy-of-vitnode-app/root/global.d.ts +1 -19
- package/copy-of-vitnode-app/root/src/components/admin-shell.tsx +2 -53
- package/copy-of-vitnode-app/root/src/components/main-footer.tsx +44 -0
- package/copy-of-vitnode-app/root/src/components/main-header.tsx +1 -30
- package/copy-of-vitnode-app/root/src/lib/i18n.ts +37 -0
- package/copy-of-vitnode-app/root/src/locales/app.ts +1 -25
- package/copy-of-vitnode-app/root/src/locales/packages.ts +1 -34
- package/copy-of-vitnode-app/root/src/router.tsx +9 -165
- package/copy-of-vitnode-app/root/src/routes/__root.tsx +12 -115
- package/copy-of-vitnode-app/root/src/routes/_admin/admin.core.index.tsx +4 -54
- package/copy-of-vitnode-app/root/src/routes/_admin.tsx +5 -198
- package/copy-of-vitnode-app/root/src/routes/_main/index.tsx +182 -46
- package/copy-of-vitnode-app/root/src/routes/_main.tsx +12 -47
- package/copy-of-vitnode-app/root/src/server/messages.server.ts +2 -23
- package/copy-of-vitnode-app/root/src/start.ts +3 -86
- package/copy-of-vitnode-app/root/src/styles.css +70 -92
- package/copy-of-vitnode-app/root/src/vitnode.config.ts +15 -53
- package/copy-of-vitnode-app/root/src/vitnode.server.config.ts +12 -0
- package/copy-of-vitnode-app/root/tsconfig.json +8 -3
- package/copy-of-vitnode-app/root/vite.config.ts +2 -99
- package/copy-of-vitnode-plugin/root/global.d.ts +6 -6
- package/dist/src/create/create-package-json.js +3 -3
- package/dist/src/create/create-vitnode.js +15 -1
- package/dist/src/create/package-versions.js +22 -22
- package/dist/src/helpers/init-git.js +38 -0
- package/dist/src/helpers/init-vitnode.js +2 -3
- package/dist/src/helpers/install-dependencies.js +2 -3
- package/dist/src/helpers/spawn-command.js +7 -0
- package/dist/src/index.js +1 -0
- package/dist/src/plugin/create/add-plugin-to-config.js +231 -0
- package/dist/src/plugin/create/create-package-json.js +2 -1
- package/dist/src/plugin/create/create-plugin-vitnode.js +23 -2
- package/dist/src/plugin/create/route-templates.js +103 -61
- package/dist/src/questions.js +7 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/copy-of-vitnode-app/api/src/i18n.ts +0 -38
- package/copy-of-vitnode-app/root/src/i18n.ts +0 -36
- package/copy-of-vitnode-app/root/src/lib/admin-auth.ts +0 -11
- package/copy-of-vitnode-app/root/src/lib/admin-nav.ts +0 -43
- package/copy-of-vitnode-app/root/src/lib/admin-search.ts +0 -37
- package/copy-of-vitnode-app/root/src/lib/auth.ts +0 -66
- package/copy-of-vitnode-app/root/src/lib/content-registry.ts +0 -51
- package/copy-of-vitnode-app/root/src/lib/document-headers.ts +0 -128
- package/copy-of-vitnode-app/root/src/lib/i18n/runtime.ts +0 -75
- package/copy-of-vitnode-app/root/src/lib/i18n/shared.ts +0 -20
- package/copy-of-vitnode-app/root/src/lib/navigation.ts +0 -24
- package/copy-of-vitnode-app/root/src/lib/page-head.ts +0 -19
- package/copy-of-vitnode-app/root/src/vitnode.shell.config.ts +0 -35
|
@@ -3,6 +3,8 @@ import type { AnyRouter } from "@tanstack/react-router";
|
|
|
3
3
|
import { createRouter as createTanStackRouter } from "@tanstack/react-router";
|
|
4
4
|
import { setupRouterSsrQueryIntegration } from "@tanstack/react-router-ssr-query";
|
|
5
5
|
import { createVitNodeQueryClient } from "@vitnode/core/lib/query-client";
|
|
6
|
+
import { createLocaleRewrite } from "@vitnode/core/tanstack/i18n";
|
|
7
|
+
import { pageHead } from "@vitnode/core/tanstack/metadata";
|
|
6
8
|
import { RoutePendingSpinner } from "@vitnode/core/tanstack/pending";
|
|
7
9
|
import {
|
|
8
10
|
pluginRouteSpecs,
|
|
@@ -14,190 +16,32 @@ import {
|
|
|
14
16
|
withCoreRootRoutes,
|
|
15
17
|
} from "@vitnode/core/tanstack/routes";
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
* The auth transport, registered by importing the module that declares it.
|
|
19
|
-
*
|
|
20
|
-
* `@vitnode/core/tanstack/auth` owns every auth decision this app makes but may
|
|
21
|
-
* not declare a `createServerFn` - uncompiled on the server, one silently
|
|
22
|
-
* resolves to `undefined` - so `lib/auth.ts` declares the eight wrappers and
|
|
23
|
-
* hands them over at module scope. A bare import because there is nothing to
|
|
24
|
-
* name: the registration *is* the module's effect.
|
|
25
|
-
*
|
|
26
|
-
* Here because a router is the one module both entry points load, so the
|
|
27
|
-
* registration has happened before any route, loader or component can reach for
|
|
28
|
-
* it, in the browser bundle and on the server alike.
|
|
29
|
-
*/
|
|
30
|
-
import "./lib/auth";
|
|
31
|
-
/**
|
|
32
|
-
* The admin transport, registered the same way and for the same reason.
|
|
33
|
-
*
|
|
34
|
-
* One server function rather than eight, reading the AdminCP's own session under
|
|
35
|
-
* its own cookie. It is a separate registration from the auth one on purpose:
|
|
36
|
-
* they are two sessions, two cookies and two cache entries, and nothing in
|
|
37
|
-
* VitNode may let the public session answer an admin question.
|
|
38
|
-
*/
|
|
39
|
-
import "./lib/admin-auth";
|
|
40
|
-
import { createLocaleRewrite, localeRouting } from "./lib/i18n/runtime";
|
|
41
|
-
import { pageHead } from "./lib/page-head";
|
|
19
|
+
import { localeRouting } from "./lib/i18n";
|
|
42
20
|
import { pluginRouteSources } from "./plugin-routes.gen";
|
|
43
21
|
import { Route as adminShellRoute } from "./routes/_admin";
|
|
44
22
|
import { Route as mainShellRoute } from "./routes/_main";
|
|
45
23
|
import { routeTree as fileRouteTree } from "./routeTree.gen";
|
|
46
24
|
|
|
47
|
-
/**
|
|
48
|
-
* The Content Engine registry, behind a literal dynamic import.
|
|
49
|
-
*
|
|
50
|
-
* Awaited by the one loader that needs it - `/admin/content/*` - rather than
|
|
51
|
-
* imported here. Building the registry reaches `@vitnode/core/content` and
|
|
52
|
-
* every configured plugin's admin form components, and this module is the one
|
|
53
|
-
* the client entry evaluates on every page: as a static import it put `zod`,
|
|
54
|
-
* every plugin's content registrations, the content form primitives and
|
|
55
|
-
* `react-hook-form` in front of the front page's first paint. See
|
|
56
|
-
* `CoreAdminRouteContext.loadContentRegistry`.
|
|
57
|
-
*/
|
|
58
25
|
const loadContentRegistry = async () =>
|
|
59
|
-
(await import("./
|
|
26
|
+
(await import("./content-registry.gen")).contentRegistry;
|
|
60
27
|
|
|
61
|
-
/**
|
|
62
|
-
* One route tree: this app's route files, plus the AdminCP screens `@vitnode/core`
|
|
63
|
-
* owns, plus the pages its plugins declare.
|
|
64
|
-
*
|
|
65
|
-
* At module scope rather than inside `getRouter`, because `getRouter` runs once
|
|
66
|
-
* per server request and mounting the plugin routes mutates the route tree - the
|
|
67
|
-
* generated tree is a module singleton. `withPluginRoutes` is idempotent anyway;
|
|
68
|
-
* doing it once is simply where it belongs.
|
|
69
|
-
*
|
|
70
|
-
* The plugin half comes from one generated file: a static import of each
|
|
71
|
-
* configured plugin's own route tree. No plugin page is copied into
|
|
72
|
-
* `src/routes`, no route path is written by hand, and nothing here knows which
|
|
73
|
-
* plugins are installed - see `@vitnode/core/tanstack/plugin-routes`.
|
|
74
|
-
*
|
|
75
|
-
* A page is reached only through the literal `lazy(() => import(...))` its route
|
|
76
|
-
* declared, so every one of them is a chunk of its own. The one part of a plugin
|
|
77
|
-
* route that is not lazy is a `search` schema: a router's `validateSearch` runs
|
|
78
|
-
* during path matching, before any chunk is fetched, so it lives in the tree
|
|
79
|
-
* rather than in the page.
|
|
80
|
-
*
|
|
81
|
-
* `mountUnder` names one route per shell, which is the whole of what "a plugin
|
|
82
|
-
* route renders in the application shell" amounts to here. A plugin declares
|
|
83
|
-
* `area: "main"` or `area: "admin"`; `_main` is the route that renders the
|
|
84
|
-
* public shell and `_admin` the one that renders the AdminCP, and being a child
|
|
85
|
-
* of one of them is what gives `/example` the header and the one `<main>` that
|
|
86
|
-
* `/discover` has, or gives `/admin/reports` the sidebar, the breadcrumb area
|
|
87
|
-
* and the admin session guard that `/admin/core` has. No new field, no per-route
|
|
88
|
-
* layout metadata and no second copy of either shell - route composition, which
|
|
89
|
-
* the area declaration already described.
|
|
90
|
-
*
|
|
91
|
-
* Neither shell changes a path: both are pathless, so `/example` stays
|
|
92
|
-
* `/example` and an admin plugin route's `/admin/…` is the path its own route
|
|
93
|
-
* spells out in full. An area VitNode knows and this app has not named here
|
|
94
|
-
* fails the composition rather than being mounted under the other one.
|
|
95
|
-
*
|
|
96
|
-
* `_main` and `_admin` are imported for their route objects, and they are the
|
|
97
|
-
* same objects the generated tree holds: `createFileRoute` produces one instance
|
|
98
|
-
* per module and `routeTree.gen.ts` mutates it in place.
|
|
99
|
-
*
|
|
100
|
-
* `withCoreMainRoutes`, `withCoreAdminRoutes` and `withCoreRootRoutes` mount
|
|
101
|
-
* core's own screens the same way, one per mount point: the public pages under
|
|
102
|
-
* the main shell, the AdminCP's under its own, and the shell-less ones - the auth
|
|
103
|
-
* cards and the AdminCP sign-in - straight under the root.
|
|
104
|
-
*
|
|
105
|
-
* They were twenty-nine route files in this application until
|
|
106
|
-
* `@vitnode/core/tanstack/routes` existed, every one of them pure wiring around
|
|
107
|
-
* something imported from the package - so an app carried a copy of VitNode's own
|
|
108
|
-
* routing table and core adding a screen meant an edit here. They are code-based
|
|
109
|
-
* rather than declared as plugin routes because they need the router's full
|
|
110
|
-
* option set: a real `validateSearch` that clamps `?page=999` before anything
|
|
111
|
-
* renders, a `beforeLoad` guard that runs before any chunk is fetched, and a
|
|
112
|
-
* splat path a plugin route path does not represent.
|
|
113
|
-
*
|
|
114
|
-
* `localeRouting` goes to the last of the three because a sign-in navigates to a
|
|
115
|
-
* path a *visitor* supplied: the route tree carries no locale, so the prefix has
|
|
116
|
-
* to be stripped before the router sees it, and which prefixes exist is this
|
|
117
|
-
* app's answer. It is the same object the `rewrite` below uses.
|
|
118
|
-
*
|
|
119
|
-
* `pageHead` is this app's own `createRouteHead(metadata)` binding, handed over
|
|
120
|
-
* because a package cannot know the site's name: a plugin page's `<title>` goes
|
|
121
|
-
* through the same `"<page> - <site>"` rule every other VitNode page's does,
|
|
122
|
-
* rather than through a second one the plugin invented.
|
|
123
|
-
*/
|
|
124
28
|
const routeTree = withCoreRootRoutes(
|
|
125
29
|
withCoreAdminRoutes(
|
|
126
30
|
withCoreMainRoutes(
|
|
127
|
-
withPluginRoutes(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
pageHead,
|
|
133
|
-
},
|
|
134
|
-
),
|
|
135
|
-
{ mountUnder: mainShellRoute, pageHead },
|
|
31
|
+
withPluginRoutes(fileRouteTree, pluginRouteSpecs(pluginRouteSources), {
|
|
32
|
+
mountUnder: { admin: adminShellRoute, main: mainShellRoute },
|
|
33
|
+
pageHead,
|
|
34
|
+
}),
|
|
35
|
+
{ localeRouting, mountUnder: mainShellRoute, pageHead },
|
|
136
36
|
),
|
|
137
37
|
{ loadContentRegistry, mountUnder: adminShellRoute, pageHead },
|
|
138
38
|
),
|
|
139
39
|
{ localeRouting, mountUnder: fileRouteTree, pageHead },
|
|
140
40
|
);
|
|
141
41
|
|
|
142
|
-
/**
|
|
143
|
-
* The app's router, and the QueryClient it owns.
|
|
144
|
-
*
|
|
145
|
-
* Start calls this once per server request and once in the browser, which is
|
|
146
|
-
* exactly the lifetime a QueryClient should have: created here, it is per
|
|
147
|
-
* request on the server - never a module-level client shared by every visitor
|
|
148
|
-
* being rendered at once - and a single long-lived one on the client.
|
|
149
|
-
*
|
|
150
|
-
* It goes into the router context, so a route loader reaches it as
|
|
151
|
-
* `context.queryClient` and can `ensureQueryData` before its component renders.
|
|
152
|
-
* That is the whole point of putting it here rather than in a provider: a
|
|
153
|
-
* loader runs before React does, so a client mounted by a component would be
|
|
154
|
-
* out of reach of the code that most wants it.
|
|
155
|
-
*
|
|
156
|
-
* `setupRouterSsrQueryIntegration` wires the two together: it dehydrates the
|
|
157
|
-
* cache into the SSR stream (including queries that resolve mid-render),
|
|
158
|
-
* hydrates it on the client before the first render, routes `redirect()` thrown
|
|
159
|
-
* inside a query or mutation through the router, and wraps the app in the one
|
|
160
|
-
* `QueryClientProvider` for this client. Nothing else in this app may create a
|
|
161
|
-
* `QueryClient` or a provider for one - two clients in a page means a query a
|
|
162
|
-
* loader cached is invisible to the component that reads it.
|
|
163
|
-
*
|
|
164
|
-
* `defaultPreloadStaleTime: 0` leaves caching to Query rather than having the
|
|
165
|
-
* router keep a second copy of the same data with its own expiry.
|
|
166
|
-
*
|
|
167
|
-
* `defaultStaleReloadMode: 'blocking'` is what makes a route's pending shape
|
|
168
|
-
* reachable at all once preloading is on. Router core's default is
|
|
169
|
-
* `'background'`, and a background reload never opens a pending window - but it
|
|
170
|
-
* still waits for the route's component chunk before it commits. So the common
|
|
171
|
-
* desktop path, hover a link and click it, took the one branch that renders
|
|
172
|
-
* nothing: the hover filled the loader, the click was therefore a background
|
|
173
|
-
* reload, and the chunk downloaded with the previous page still on screen and
|
|
174
|
-
* no skeleton in sight.
|
|
175
|
-
*
|
|
176
|
-
* It costs nothing here because a VitNode loader does not block on a warm cache:
|
|
177
|
-
* `ensureQueryData` with `revalidateIfStale` hands back the cached entry and
|
|
178
|
-
* refreshes behind it, so "blocking" describes a promise that resolves in a
|
|
179
|
-
* microtask. What changes is only that the router now marks the match pending
|
|
180
|
-
* while that happens, which is what `defaultPendingMs` is for.
|
|
181
|
-
*
|
|
182
|
-
* `defaultPendingMs: 150` is that threshold, and it is not zero for the same
|
|
183
|
-
* reason. At zero, every navigation opens a pending window, so
|
|
184
|
-
* `defaultPendingMinMs` holds a *fully cached* navigation behind a skeleton for
|
|
185
|
-
* 300ms - a page that could have been instant, made slow to look busy. At 150ms
|
|
186
|
-
* a cached navigation goes straight through with nothing shown and a slow one
|
|
187
|
-
* still gets its shape, in the content area and the breadcrumb together.
|
|
188
|
-
*
|
|
189
|
-
* `rewrite` is what makes one route tree serve two public URL shapes: `/pl/...`
|
|
190
|
-
* arrives, `/...` is matched, and every link the router builds gets the prefix
|
|
191
|
-
* back. No route file mentions a locale, so nothing here has to be duplicated
|
|
192
|
-
* per language - see `@vitnode/core/tanstack/i18n`.
|
|
193
|
-
*/
|
|
194
42
|
export function getRouter() {
|
|
195
43
|
const queryClient = createVitNodeQueryClient();
|
|
196
44
|
|
|
197
|
-
// The rewrite reads the locale off the router's own current location, and the
|
|
198
|
-
// router needs the rewrite to parse that location - so it is handed a getter
|
|
199
|
-
// rather than the router itself. `output` only ever runs once a link is built,
|
|
200
|
-
// which is long after the assignment below.
|
|
201
45
|
const holder: { current?: AnyRouter } = {};
|
|
202
46
|
|
|
203
47
|
const router = createTanStackRouter({
|
|
@@ -16,41 +16,21 @@ import {
|
|
|
16
16
|
resolveLocale,
|
|
17
17
|
useLocale,
|
|
18
18
|
} from "@vitnode/core/tanstack/i18n";
|
|
19
|
-
import {
|
|
20
|
-
ErrorActions,
|
|
21
|
-
NotFound,
|
|
22
|
-
VitNodeRootProviders,
|
|
23
|
-
} from "@vitnode/core/tanstack/layout";
|
|
19
|
+
import { VitNodeRootProviders } from "@vitnode/core/tanstack/layout";
|
|
24
20
|
|
|
25
|
-
import type { Locale } from "
|
|
21
|
+
import type { Locale } from "@/vitnode.config";
|
|
26
22
|
|
|
27
|
-
import {
|
|
23
|
+
import { vitNodeConfig } from "@/vitnode.config";
|
|
28
24
|
|
|
29
25
|
import appCss from "../styles.css?url";
|
|
30
26
|
|
|
31
|
-
const { debug, i18n, metadata, theme } =
|
|
27
|
+
const { debug, editor, i18n, metadata, theme } = vitNodeConfig;
|
|
32
28
|
|
|
33
|
-
/**
|
|
34
|
-
* What the router itself provides, before any route has run.
|
|
35
|
-
*
|
|
36
|
-
* The QueryClient, and nothing else. `beforeLoad` below adds `locale` on top, so
|
|
37
|
-
* what a loader actually receives is `{ queryClient, locale }` - the language
|
|
38
|
-
* included, because a loader that fetches anything user-facing needs to know
|
|
39
|
-
* which one it is fetching.
|
|
40
|
-
*/
|
|
41
29
|
export interface RootRouterContext {
|
|
42
30
|
queryClient: QueryClient;
|
|
43
31
|
}
|
|
44
32
|
|
|
45
33
|
export const Route = createRootRouteWithContext<RootRouterContext>()({
|
|
46
|
-
/**
|
|
47
|
-
* The request's language, resolved once and handed to every loader below.
|
|
48
|
-
*
|
|
49
|
-
* The same function the rewrite and the components use, so there is one answer
|
|
50
|
-
* per request rather than one per consumer. Note that a language switch does
|
|
51
|
-
* not change the *internal* URL - only the public one - so the switcher
|
|
52
|
-
* invalidates the router to bring this back in step.
|
|
53
|
-
*/
|
|
54
34
|
beforeLoad: ({ location }) => ({
|
|
55
35
|
locale: resolveLocale<Locale>(publicPathnameOf(location)),
|
|
56
36
|
}),
|
|
@@ -58,16 +38,7 @@ export const Route = createRootRouteWithContext<RootRouterContext>()({
|
|
|
58
38
|
head: () => ({
|
|
59
39
|
links: [
|
|
60
40
|
{ href: appCss, rel: "stylesheet" },
|
|
61
|
-
|
|
62
|
-
* The tab icon, from `public/favicon.ico`.
|
|
63
|
-
*
|
|
64
|
-
* Stated rather than left to the browser's automatic `/favicon.ico`
|
|
65
|
-
* request, because that request is a 404 until the file exists and a
|
|
66
|
-
* silently missing icon is easy to never notice. Drop your own 32px `.ico`
|
|
67
|
-
* at `public/favicon.ico`; it lives there rather than being imported so
|
|
68
|
-
* that the URL is stable and the file is still reachable at the well-known
|
|
69
|
-
* path browsers ask for unprompted.
|
|
70
|
-
*/
|
|
41
|
+
|
|
71
42
|
{
|
|
72
43
|
href: "/favicon.ico",
|
|
73
44
|
rel: "icon",
|
|
@@ -78,102 +49,28 @@ export const Route = createRootRouteWithContext<RootRouterContext>()({
|
|
|
78
49
|
meta: [
|
|
79
50
|
{ charSet: "utf-8" },
|
|
80
51
|
{ content: "width=device-width, initial-scale=1", name: "viewport" },
|
|
81
|
-
// The default title, from the app's config. A route that names itself
|
|
82
|
-
// renders `"<page> - <shortTitle>"` instead, through `formatPageTitle` -
|
|
83
|
-
// the same rule Next.js applies through `title.template`.
|
|
84
52
|
{ title: metadata.title },
|
|
85
53
|
],
|
|
86
54
|
}),
|
|
87
|
-
/**
|
|
88
|
-
* Warm this language's shell strings before anything renders.
|
|
89
|
-
*
|
|
90
|
-
* `context.locale` rather than a default: `/pl` has to arrive with Polish
|
|
91
|
-
* already in the cache, or the first paint is English and the page flips after
|
|
92
|
-
* hydration.
|
|
93
|
-
*/
|
|
94
55
|
loader: async ({ context }) => {
|
|
95
|
-
await context.queryClient.
|
|
96
|
-
intlQueryOptions({ locale: context.locale }),
|
|
97
|
-
|
|
56
|
+
await context.queryClient.query({
|
|
57
|
+
...intlQueryOptions({ locale: context.locale }),
|
|
58
|
+
staleTime: "static",
|
|
59
|
+
});
|
|
98
60
|
},
|
|
99
|
-
/**
|
|
100
|
-
* Every URL this application does not serve.
|
|
101
|
-
*
|
|
102
|
-
* The last resort, and until now there was none: a path that matched no route
|
|
103
|
-
* at all fell through to TanStack Router's own `<p>Not Found</p>` - no shell,
|
|
104
|
-
* no strings, no way back - and the router warned about the missing option on
|
|
105
|
-
* every such navigation. `/admin/contents` and a hand-typed `/blog/post-30`
|
|
106
|
-
* both landed there.
|
|
107
|
-
*
|
|
108
|
-
* ## What reaches it, and what does not
|
|
109
|
-
*
|
|
110
|
-
* Only a path **no route matched**. A route that matched and then answered
|
|
111
|
-
* `notFound()` from its own loader is caught by the nearest
|
|
112
|
-
* `notFoundComponent` above it, which is why `/admin/content/nope` and
|
|
113
|
-
* `/admin/content/blog/articles/999999/edit` render the AdminCP's 404 inside
|
|
114
|
-
* the panel rather than this - see `_admin`'s, which mounts the shell around
|
|
115
|
-
* the same message.
|
|
116
|
-
*
|
|
117
|
-
* ## It is a 404, and not a redirect anywhere
|
|
118
|
-
*
|
|
119
|
-
* The route tree is the whole application, so a URL that reaches here is one
|
|
120
|
-
* somebody typed or a stale bookmark, and saying so is the honest answer.
|
|
121
|
-
* Bouncing an unmatched path at some other origin would hide a genuinely
|
|
122
|
-
* missing page behind a hop to a server that 404s it anyway. Where a URL is
|
|
123
|
-
* served from is a deployment question, and a proxy in front of the app
|
|
124
|
-
* answers it better than this route can.
|
|
125
|
-
*/
|
|
126
|
-
notFoundComponent: RootNotFound,
|
|
127
61
|
shellComponent: RootDocument,
|
|
128
62
|
});
|
|
129
63
|
|
|
130
|
-
/**
|
|
131
|
-
* Rendered inside `RootComponent`, which is what makes the strings work: the
|
|
132
|
-
* providers it mounts include `RouteMessages` with `core.global`, and that is
|
|
133
|
-
* the namespace `NotFound` reads its two lines from. The root's loader has
|
|
134
|
-
* already warmed that entry, so nothing suspends.
|
|
135
|
-
*/
|
|
136
|
-
function RootNotFound() {
|
|
137
|
-
return <NotFound actions={<ErrorActions />} />;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* The VitNode provider tree, mounted once above every route.
|
|
142
|
-
*
|
|
143
|
-
* Every provider in it is shared with the Next.js app - the theme, the toaster,
|
|
144
|
-
* the tooltip provider, the WebSocket - plus the pair of `use-intl` records that
|
|
145
|
-
* only a package can name. `VitNodeRootProviders` owns all of it, including the
|
|
146
|
-
* argument for why the realtime listeners are inside it rather than in the main
|
|
147
|
-
* shell.
|
|
148
|
-
*
|
|
149
|
-
* What this route contributes is the two things an application owns: which
|
|
150
|
-
* languages it serves, and its theme defaults.
|
|
151
|
-
*
|
|
152
|
-
* Because the locale comes from router state, changing language re-renders this:
|
|
153
|
-
* new locale, new query key, new messages, no page reload.
|
|
154
|
-
*/
|
|
155
64
|
function RootComponent() {
|
|
156
65
|
return (
|
|
157
|
-
<VitNodeRootProviders
|
|
66
|
+
<VitNodeRootProviders
|
|
67
|
+
config={{ debug, editor, locales: i18n.locales, theme }}
|
|
68
|
+
>
|
|
158
69
|
<Outlet />
|
|
159
70
|
</VitNodeRootProviders>
|
|
160
71
|
);
|
|
161
72
|
}
|
|
162
73
|
|
|
163
|
-
/**
|
|
164
|
-
* The document itself.
|
|
165
|
-
*
|
|
166
|
-
* `lang` is the language this request actually resolved to - `en` for `/`, `pl`
|
|
167
|
-
* for `/pl`, and on a route outside the localized URL space (`/admin`) whatever
|
|
168
|
-
* the visitor's cookie says. It comes from the same router state the provider
|
|
169
|
-
* reads, so the two cannot disagree and hydration has nothing to complain about.
|
|
170
|
-
*
|
|
171
|
-
* `ThemeScript` has to be in the head, and it has to be inline: it applies the
|
|
172
|
-
* stored theme to `<html>` before the browser paints, so the first frame is the
|
|
173
|
-
* theme the visitor chose rather than a flash of the default one.
|
|
174
|
-
* `suppressHydrationWarning` covers the attributes it writes, which by design
|
|
175
|
-
* differ from what the server rendered.
|
|
176
|
-
*/
|
|
177
74
|
function RootDocument({ children }: { children: React.ReactNode }) {
|
|
178
75
|
const locale = useLocale();
|
|
179
76
|
|
|
@@ -1,67 +1,17 @@
|
|
|
1
1
|
import { createFileRoute } from "@tanstack/react-router";
|
|
2
|
-
import {
|
|
2
|
+
import { adminBreadcrumb } from "@vitnode/core/tanstack/admin";
|
|
3
3
|
import {
|
|
4
4
|
AdminDashboardRouteContent,
|
|
5
5
|
loadAdminDashboardRoute,
|
|
6
6
|
} from "@vitnode/core/tanstack/admin/dashboard";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
* `/admin/core` - the AdminCP dashboard, and the one route file `_admin` keeps.
|
|
10
|
-
*
|
|
11
|
-
* Topology only. The layout query, the widget catalogue, the drag-and-drop
|
|
12
|
-
* board, the settings dialogs and the four mutations behind them are
|
|
13
|
-
* `@vitnode/core/tanstack/admin/dashboard`.
|
|
14
|
-
*
|
|
15
|
-
* ## Why this one file is still here
|
|
16
|
-
*
|
|
17
|
-
* Every other AdminCP screen is `@vitnode/core`'s, mounted by
|
|
18
|
-
* `withCoreAdminRoutes` as a code-based route - see `src/router.tsx`. This one
|
|
19
|
-
* stays because the file-based generator requires it to, and the requirement is
|
|
20
|
-
* sharp rather than stylistic:
|
|
21
|
-
*
|
|
22
|
-
* - A pathless layout with no file children is **dropped from the generated
|
|
23
|
-
* tree**. `buildRouteTreeConfig` skips it outright, so `_admin` would not be
|
|
24
|
-
* in `routeTree.gen.ts` at all and the route object `src/router.tsx` mounts
|
|
25
|
-
* core's screens under would be an orphan.
|
|
26
|
-
* - It also collapses to a full path of `/`, which collides with `_main/index.tsx`
|
|
27
|
-
* and fails the generator's uniqueness check by name.
|
|
28
|
-
*
|
|
29
|
-
* So `_admin` needs one file-based child with a real path in order to exist, and
|
|
30
|
-
* this is it - which is the same job it has always had. It was the shell's first
|
|
31
|
-
* child for exactly this reason, and now it is the only one.
|
|
32
|
-
*
|
|
33
|
-
* Deleting it does not remove a screen; it removes the AdminCP.
|
|
34
|
-
*
|
|
35
|
-
* ## No `head`, deliberately
|
|
36
|
-
*
|
|
37
|
-
* The Next.js page exports no `generateMetadata`, so the tab keeps the site's
|
|
38
|
-
* own name. Declaring `title: 'VitNode'` here would render "VitNode - VitNode"
|
|
39
|
-
* through `formatPageTitle`; saying nothing inherits the root's title and
|
|
40
|
-
* `_admin`'s `noindex`, which is the parity-preserving answer.
|
|
41
|
-
*
|
|
42
|
-
* ## `pluginWidgets` is not passed
|
|
43
|
-
*
|
|
44
|
-
* A plugin's dashboard widgets reach the Next.js board through
|
|
45
|
-
* `getVitNodeConfig()`, which is server-side config kept out of this app's
|
|
46
|
-
* browser bundle by `vitnode.shell.config.ts` - and this app registers its
|
|
47
|
-
* plugins by id and messages only (see `src/vitnode.config.ts`). So the board
|
|
48
|
-
* shows core's own widgets, which is the complete set for this install. It is
|
|
49
|
-
* the same seam `AdminShell` leaves open for nav `declarations`, and it changes
|
|
50
|
-
* here when plugin AdminCP registration moves over.
|
|
51
|
-
*/
|
|
8
|
+
|
|
52
9
|
export const Route = createFileRoute("/_admin/admin/core/")({
|
|
53
10
|
loader: async ({ context }) => await loadAdminDashboardRoute(context),
|
|
54
11
|
component: AdminDashboardRoute,
|
|
55
|
-
|
|
56
|
-
* The whole of how an admin route contributes to the trail in the shell's
|
|
57
|
-
* header: the route declares its own crumb next to its own component, the
|
|
58
|
-
* shell renders whichever matched route declared the deepest one, and there is
|
|
59
|
-
* no map from pathname to breadcrumb anywhere. The label comes from the
|
|
60
|
-
* *visible* navigation, so this reads "Core" in whatever language the
|
|
61
|
-
* administrator is using without this file naming a string.
|
|
62
|
-
*/
|
|
12
|
+
|
|
63
13
|
staticData: {
|
|
64
|
-
breadcrumb:
|
|
14
|
+
breadcrumb: adminBreadcrumb({ segments: ["core"] }),
|
|
65
15
|
},
|
|
66
16
|
});
|
|
67
17
|
|