@powerhousedao/connect 6.2.3-dev.61 → 6.2.3-dev.63
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 +101 -0
- package/dist/{AddDriveModal-C5odBO8y.js → AddDriveModal-D_3jDwjp.js} +6 -6
- package/dist/AddDriveModal-D_3jDwjp.js.map +1 -0
- package/dist/{ClearStorageModal-nzpz8MeW.js → ClearStorageModal-CAPjV674.js} +9 -11
- package/dist/ClearStorageModal-CAPjV674.js.map +1 -0
- package/dist/{ConfirmDocumentUpgradeModal-k79v2wM6.js → ConfirmDocumentUpgradeModal-CrU2Z1CL.js} +5 -5
- package/dist/{ConfirmDocumentUpgradeModal-k79v2wM6.js.map → ConfirmDocumentUpgradeModal-CrU2Z1CL.js.map} +1 -1
- package/dist/{CookiesPolicyModal-BLw4pnhn.js → CookiesPolicyModal-DQwsgDI9.js} +5 -5
- package/dist/{CookiesPolicyModal-BLw4pnhn.js.map → CookiesPolicyModal-DQwsgDI9.js.map} +1 -1
- package/dist/{CreateDocumentModal-Bmv0V-kY.js → CreateDocumentModal-Cf1APibL.js} +4 -4
- package/dist/{CreateDocumentModal-Bmv0V-kY.js.map → CreateDocumentModal-Cf1APibL.js.map} +1 -1
- package/dist/{DebugSettingsModal-BW0HWI1D.js → DebugSettingsModal-CuxHqpMv.js} +8 -8
- package/dist/{DebugSettingsModal-BW0HWI1D.js.map → DebugSettingsModal-CuxHqpMv.js.map} +1 -1
- package/dist/{DeleteDriveModal-CjGnG0ht.js → DeleteDriveModal-lE9eCBua.js} +5 -5
- package/dist/{DeleteDriveModal-CjGnG0ht.js.map → DeleteDriveModal-lE9eCBua.js.map} +1 -1
- package/dist/{DeleteItemModal-BbY_4_xT.js → DeleteItemModal-BFgcGsm3.js} +6 -6
- package/dist/{DeleteItemModal-BbY_4_xT.js.map → DeleteItemModal-BFgcGsm3.js.map} +1 -1
- package/dist/{DisclaimerModal-DuglmEwL.js → DisclaimerModal-CF6JkIIu.js} +6 -6
- package/dist/{DisclaimerModal-DuglmEwL.js.map → DisclaimerModal-CF6JkIIu.js.map} +1 -1
- package/dist/{DocumentVersionUnsupportedModal-C4fy7fZ6.js → DocumentVersionUnsupportedModal-Cm9Jb9W7.js} +5 -5
- package/dist/DocumentVersionUnsupportedModal-Cm9Jb9W7.js.map +1 -0
- package/dist/{DownloadDocumentWithErrorsModal-BsPQ5qgy.js → DownloadDocumentWithErrorsModal-CShKhfEQ.js} +5 -5
- package/dist/{DownloadDocumentWithErrorsModal-BsPQ5qgy.js.map → DownloadDocumentWithErrorsModal-CShKhfEQ.js.map} +1 -1
- package/dist/{DriveAuthRequiredModal-CtsB0kwH.js → DriveAuthRequiredModal-CMwPUyZf.js} +5 -5
- package/dist/{DriveAuthRequiredModal-CtsB0kwH.js.map → DriveAuthRequiredModal-CMwPUyZf.js.map} +1 -1
- package/dist/{DriveSettingsModal-d1L0eYof.js → DriveSettingsModal-BSImj4BH.js} +5 -5
- package/dist/{DriveSettingsModal-d1L0eYof.js.map → DriveSettingsModal-BSImj4BH.js.map} +1 -1
- package/dist/FloatingTanStackRouterDevtools-CqogiFob-dxj8lrTP.js +2565 -0
- package/dist/FloatingTanStackRouterDevtools-CqogiFob-dxj8lrTP.js.map +1 -0
- package/dist/{InspectorModal-Dpf-3LVT.js → InspectorModal-BQBTvrkT.js} +9 -9
- package/dist/{InspectorModal-Dpf-3LVT.js.map → InspectorModal-BQBTvrkT.js.map} +1 -1
- package/dist/{LoginModal-CI0ogC2-.js → LoginModal-DT_05uva.js} +6 -6
- package/dist/{LoginModal-CI0ogC2-.js.map → LoginModal-DT_05uva.js.map} +1 -1
- package/dist/{MissingPackageModal-DS3dgJ1K.js → MissingPackageModal-DtISKgub.js} +6 -6
- package/dist/{MissingPackageModal-DS3dgJ1K.js.map → MissingPackageModal-DtISKgub.js.map} +1 -1
- package/dist/{OpenFileDocumentsModal-BOmFtxS1.js → OpenFileDocumentsModal-X9GnX2Bk.js} +13 -12
- package/dist/OpenFileDocumentsModal-X9GnX2Bk.js.map +1 -0
- package/dist/{UpgradeDriveModal-CXX6D5Au.js → UpgradeDriveModal-DvM-PNWe.js} +6 -6
- package/dist/{UpgradeDriveModal-CXX6D5Au.js.map → UpgradeDriveModal-DvM-PNWe.js.map} +1 -1
- package/dist/app-layout-BIq-ZW-6.js +394 -0
- package/dist/app-layout-BIq-ZW-6.js.map +1 -0
- package/dist/app-loader-Dig98EdR.js +1291 -0
- package/dist/app-loader-Dig98EdR.js.map +1 -0
- package/dist/app-loader-YjBKjkOv.js +4 -0
- package/dist/{app-skeleton-CBN4tenZ.js → app-skeleton-DYLZ7npI.js} +3 -3
- package/dist/{app-skeleton--Me5zlSz.js → app-skeleton-gzg8cRzm.js} +7 -7
- package/dist/app-skeleton-gzg8cRzm.js.map +1 -0
- package/dist/{boot-CNW7ypcB.js → boot-CC_DgQKX.js} +32 -9
- package/dist/boot-CC_DgQKX.js.map +1 -0
- package/dist/{build-info-DNKZUbvY.js → build-info-CTKeq43y.js} +5 -5
- package/dist/{build-info-DNKZUbvY.js.map → build-info-CTKeq43y.js.map} +1 -1
- package/dist/components-DzTqdJzC.js +120 -0
- package/dist/components-DzTqdJzC.js.map +1 -0
- package/dist/connect-router-KmNBGS0G.js +434 -0
- package/dist/connect-router-KmNBGS0G.js.map +1 -0
- package/dist/{connect.config-CB78ZsFz.js → connect.config-uZF-gnvV.js} +7 -7
- package/dist/{connect.config-CB78ZsFz.js.map → connect.config-uZF-gnvV.js.map} +1 -1
- package/dist/{connection-state-BDikOGKo.js → connection-state-C_477Kr_.js} +6 -6
- package/dist/{connection-state-BDikOGKo.js.map → connection-state-C_477Kr_.js.map} +1 -1
- package/dist/context-De2EB1AA-Ni0d829Q.js +1759 -0
- package/dist/context-De2EB1AA-Ni0d829Q.js.map +1 -0
- package/dist/{cookie-banner-D05DZRqY.js → cookie-banner-HPgyuHM5.js} +6 -6
- package/dist/{cookie-banner-D05DZRqY.js.map → cookie-banner-HPgyuHM5.js.map} +1 -1
- package/dist/drive-icon-BiVP8yJc.js +38 -0
- package/dist/drive-icon-BiVP8yJc.js.map +1 -0
- package/dist/esm-BDACZntJ.js +148 -0
- package/dist/esm-BDACZntJ.js.map +1 -0
- package/dist/index-UrZFqSgm.d.ts +166 -0
- package/dist/index-UrZFqSgm.d.ts.map +1 -0
- package/dist/layout.d.ts +29 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +6 -0
- package/dist/{load-BxQ82Cxc.js → load-f-BRwdCc.js} +48 -48
- package/dist/load-f-BRwdCc.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/{multi-reactor-BG-DqUcm.js → multi-reactor-fSKpLBjT.js} +10 -7
- package/dist/multi-reactor-fSKpLBjT.js.map +1 -0
- package/dist/open-file-uploads-BcyWmUZn.js +183 -0
- package/dist/open-file-uploads-BcyWmUZn.js.map +1 -0
- package/dist/{package-manager-BPVMRBoV.js → package-manager-BkFRzovd.js} +52 -45
- package/dist/package-manager-BkFRzovd.js.map +1 -0
- package/dist/{pglite-migrate-core-BcXcImng.js → pglite-migrate-core-DBlU6HIc.js} +4 -4
- package/dist/pglite-migrate-core-DBlU6HIc.js.map +1 -0
- package/dist/{pglite-seed-CQJ97bEt.js → pglite-seed-BsEPByVM.js} +4 -4
- package/dist/{pglite-seed-CQJ97bEt.js.map → pglite-seed-BsEPByVM.js.map} +1 -1
- package/dist/{preferences-store-Cm0BoiHA.js → preferences-store-DANUajdg.js} +4 -4
- package/dist/{preferences-store-Cm0BoiHA.js.map → preferences-store-DANUajdg.js.map} +1 -1
- package/dist/prerendered-shell-DxCUDEXL.js +45 -0
- package/dist/prerendered-shell-DxCUDEXL.js.map +1 -0
- package/dist/{reactor-DHJyk5ow.js → reactor-B_aOB2bl.js} +50 -46
- package/dist/reactor-B_aOB2bl.js.map +1 -0
- package/dist/reactor-chat-LAB-9G3G.js +50 -0
- package/dist/reactor-chat-LAB-9G3G.js.map +1 -0
- package/dist/reactor.worker.js +85 -27
- package/dist/reactor.worker.js.map +1 -1
- package/dist/{registerServiceWorker-DT6t8wjg.js → registerServiceWorker-CkVxA2KC.js} +4 -4
- package/dist/{registerServiceWorker-DT6t8wjg.js.map → registerServiceWorker-CkVxA2KC.js.map} +1 -1
- package/dist/route-components-BkztQruF.js +148 -0
- package/dist/route-components-BkztQruF.js.map +1 -0
- package/dist/route-tree.d.ts +2229 -0
- package/dist/route-tree.d.ts.map +1 -0
- package/dist/route-tree.js +211 -0
- package/dist/route-tree.js.map +1 -0
- package/dist/router-BQACPBhO.js +4 -0
- package/dist/router-CLly15sT.js +604 -0
- package/dist/router-CLly15sT.js.map +1 -0
- package/dist/router.d.ts +4 -0
- package/dist/router.js +7 -0
- package/dist/{runtime-config-DI5OfIC6.js → runtime-config-DdN1Frg7.js} +6 -9
- package/dist/runtime-config-DdN1Frg7.js.map +1 -0
- package/dist/{sentry-jfDyrxdX.js → sentry-CJb7--mu.js} +7 -4
- package/dist/{sentry-jfDyrxdX.js.map → sentry-CJb7--mu.js.map} +1 -1
- package/dist/settings-CjvK8OKA.js +91 -0
- package/dist/settings-CjvK8OKA.js.map +1 -0
- package/dist/{SettingsModal-BJVPEHbo.js → settings-KUPb4Ccj.js} +126 -83
- package/dist/settings-KUPb4Ccj.js.map +1 -0
- package/dist/shell-head.html +1 -0
- package/dist/shell.html +1 -0
- package/dist/sidebar-BXf8OEwm.d.ts +34 -0
- package/dist/sidebar-BXf8OEwm.d.ts.map +1 -0
- package/dist/sidebar-lAVFRsni.js +31 -0
- package/dist/sidebar-lAVFRsni.js.map +1 -0
- package/dist/start-connect.d.ts +4 -1
- package/dist/start-connect.d.ts.map +1 -1
- package/dist/start-connect.js +9 -5
- package/dist/start-connect.js.map +1 -1
- package/dist/style.css +36 -18
- package/dist/{useRegistryPackages-3EcR3GOh.js → useRegistryPackages-BqIWwXV-.js} +5 -5
- package/dist/{useRegistryPackages-3EcR3GOh.js.map → useRegistryPackages-BqIWwXV-.js.map} +1 -1
- package/fonts.css +177 -0
- package/package.json +51 -22
- package/scripts/critical-css.ts +243 -0
- package/scripts/prerender-shell.ts +100 -0
- package/src/routeTree.gen.ts +293 -0
- package/src/router/connect-router.ts +170 -0
- package/src/router/drive-route-loader.ts +116 -0
- package/src/router/index.ts +51 -0
- package/src/router/navigation.ts +230 -0
- package/src/router/perf-marks.test.tsx +98 -0
- package/src/router/perf-marks.ts +97 -0
- package/src/router/register.ts +9 -0
- package/src/router/route-components.tsx +98 -0
- package/src/router/route-tree.ts +88 -0
- package/src/router/scroll.ts +69 -0
- package/src/router/search.ts +66 -0
- package/src/router/settings.ts +120 -0
- package/src/router/sidebar.ts +55 -0
- package/src/router/titles.test.ts +24 -0
- package/src/router/titles.ts +33 -0
- package/src/routes/__root.tsx +28 -0
- package/src/routes/core/_app/$.tsx +13 -0
- package/src/routes/core/_app/_content/d/$driveSlug/{-$nodeSlug}.tsx +52 -0
- package/src/routes/core/_app/_content/index.tsx +3 -0
- package/src/routes/core/_app/_content.tsx +9 -0
- package/src/routes/core/_app/settings/about.tsx +20 -0
- package/src/routes/core/_app/settings/ai-assistant.tsx +20 -0
- package/src/routes/core/_app/settings/danger-zone.tsx +21 -0
- package/src/routes/core/_app/settings/default-editors.tsx +20 -0
- package/src/routes/core/_app/settings/package-manager.tsx +20 -0
- package/src/routes/core/_app/settings.tsx +35 -0
- package/src/routes/core/_app.tsx +10 -0
- package/dist/AddDriveModal-C5odBO8y.js.map +0 -1
- package/dist/ClearStorageModal-nzpz8MeW.js.map +0 -1
- package/dist/DocumentVersionUnsupportedModal-C4fy7fZ6.js.map +0 -1
- package/dist/OpenFileDocumentsModal-BOmFtxS1.js.map +0 -1
- package/dist/SettingsModal-BJVPEHbo.js.map +0 -1
- package/dist/app-loader-CNCzLxgV.js +0 -2379
- package/dist/app-loader-CNCzLxgV.js.map +0 -1
- package/dist/app-loader-DvnGgSyC.js +0 -4
- package/dist/app-skeleton--Me5zlSz.js.map +0 -1
- package/dist/boot-CNW7ypcB.js.map +0 -1
- package/dist/components-BKUI79po.js +0 -5
- package/dist/load-BxQ82Cxc.js.map +0 -1
- package/dist/multi-reactor-BG-DqUcm.js.map +0 -1
- package/dist/package-manager-BPVMRBoV.js.map +0 -1
- package/dist/pglite-migrate-core-BcXcImng.js.map +0 -1
- package/dist/reactor-DHJyk5ow.js.map +0 -1
- package/dist/runtime-config-DI5OfIC6.js.map +0 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { AnyRouter } from "@tanstack/react-router";
|
|
2
|
+
|
|
3
|
+
/** `localStorage[PERF_STORAGE_KEY] = "1"` or `?perf=1` turns the marks on in production. */
|
|
4
|
+
export const PERF_STORAGE_KEY = "ph:perf";
|
|
5
|
+
|
|
6
|
+
/** The measures each navigation writes, as the bench reads them. */
|
|
7
|
+
export const ROUTER_MEASURES = {
|
|
8
|
+
/** `navigation.open` to the router starting the navigation. */
|
|
9
|
+
click: "nav click",
|
|
10
|
+
/** Route loaders, until the router commits the matches. */
|
|
11
|
+
loader: "nav loader",
|
|
12
|
+
/** The commit until React has rendered it. */
|
|
13
|
+
commit: "nav commit",
|
|
14
|
+
/** The click (or the navigation's start) to the next frame after render. */
|
|
15
|
+
total: "nav total",
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
// Chrome's Performance panel shows these as "Connect › Router".
|
|
19
|
+
const DETAIL = {
|
|
20
|
+
devtools: { dataType: "track-entry", track: "Router", trackGroup: "Connect" },
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
let marking = 0;
|
|
24
|
+
let clickedAt: number | undefined;
|
|
25
|
+
|
|
26
|
+
/** On in dev builds; elsewhere only with the runtime flag. */
|
|
27
|
+
export function routerPerfEnabled(dev: boolean = import.meta.env.DEV) {
|
|
28
|
+
if (dev) return true;
|
|
29
|
+
try {
|
|
30
|
+
return (
|
|
31
|
+
new URLSearchParams(location.search).get("perf") === "1" ||
|
|
32
|
+
localStorage.getItem(PERF_STORAGE_KEY) === "1"
|
|
33
|
+
);
|
|
34
|
+
} catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Marks a navigation's click; a no-op unless a router is being marked. */
|
|
40
|
+
export function markNavigationClick() {
|
|
41
|
+
if (!marking) return;
|
|
42
|
+
clickedAt = performance.now();
|
|
43
|
+
performance.mark("nav:click", { detail: DETAIL });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function measure(name: string, start: number | undefined, end: number) {
|
|
47
|
+
if (start === undefined) return;
|
|
48
|
+
performance.measure(name, { start, end, detail: DETAIL });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Writes each navigation's phases as performance measures; returns the unsubscribe. */
|
|
52
|
+
export function markRouterNavigations(
|
|
53
|
+
router: Pick<AnyRouter, "subscribe">,
|
|
54
|
+
enabled = routerPerfEnabled(),
|
|
55
|
+
) {
|
|
56
|
+
if (!enabled) return () => {};
|
|
57
|
+
marking++;
|
|
58
|
+
let generation = 0;
|
|
59
|
+
let clicked: number | undefined;
|
|
60
|
+
let navigated: number | undefined;
|
|
61
|
+
let loading: number | undefined;
|
|
62
|
+
let loaded: number | undefined;
|
|
63
|
+
const unsubscribes = [
|
|
64
|
+
router.subscribe("onBeforeNavigate", () => {
|
|
65
|
+
generation++;
|
|
66
|
+
navigated = performance.now();
|
|
67
|
+
clicked = clickedAt;
|
|
68
|
+
clickedAt = undefined;
|
|
69
|
+
measure(ROUTER_MEASURES.click, clicked, navigated);
|
|
70
|
+
loading = loaded = undefined;
|
|
71
|
+
}),
|
|
72
|
+
router.subscribe("onBeforeLoad", () => {
|
|
73
|
+
loading = performance.now();
|
|
74
|
+
}),
|
|
75
|
+
router.subscribe("onLoad", () => {
|
|
76
|
+
loaded = performance.now();
|
|
77
|
+
measure(ROUTER_MEASURES.loader, loading, loaded);
|
|
78
|
+
}),
|
|
79
|
+
router.subscribe("onRendered", () => {
|
|
80
|
+
measure(ROUTER_MEASURES.commit, loaded, performance.now());
|
|
81
|
+
const current = generation;
|
|
82
|
+
const start = clicked ?? navigated;
|
|
83
|
+
// The frame after render, as close to paint as a script sees.
|
|
84
|
+
requestAnimationFrame(() =>
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
if (current === generation) {
|
|
87
|
+
measure(ROUTER_MEASURES.total, start, performance.now());
|
|
88
|
+
}
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
}),
|
|
92
|
+
];
|
|
93
|
+
return () => {
|
|
94
|
+
marking--;
|
|
95
|
+
for (const unsubscribe of unsubscribes) unsubscribe();
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Connect's own router type. Nothing imports this file, so it stays out of the
|
|
2
|
+
// declarations projects see; their generated tree registers their router.
|
|
3
|
+
import type { ConnectRouter } from "./connect-router.js";
|
|
4
|
+
|
|
5
|
+
declare module "@tanstack/react-router" {
|
|
6
|
+
interface Register {
|
|
7
|
+
router: ConnectRouter;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ErrorRouteComponent,
|
|
3
|
+
RouteComponent,
|
|
4
|
+
} from "@tanstack/react-router";
|
|
5
|
+
import { HeadContent, Outlet, useRouter } from "@tanstack/react-router";
|
|
6
|
+
import type { ComponentType } from "react";
|
|
7
|
+
|
|
8
|
+
export type ConnectRouteComponents = {
|
|
9
|
+
/** What every page shares; it renders an `<Outlet />`. */
|
|
10
|
+
root: RouteComponent;
|
|
11
|
+
/** The `_app` layout, e.g. the sidebar; it renders an `<Outlet />`. */
|
|
12
|
+
app?: RouteComponent;
|
|
13
|
+
/** Stays mounted between the home and drive views. */
|
|
14
|
+
content: RouteComponent;
|
|
15
|
+
/** Unknown paths and loaders' notFound(), inside the layout. */
|
|
16
|
+
notFound?: RouteComponent;
|
|
17
|
+
drivePending?: RouteComponent;
|
|
18
|
+
/** A drive that is not listed once arrivals settle; `notFound` without it. */
|
|
19
|
+
driveNotFound?: ComponentType<{ driveSlug: string }>;
|
|
20
|
+
/** Any route's loader or render error. */
|
|
21
|
+
error?: ErrorRouteComponent;
|
|
22
|
+
/** The settings page around its tabs; it renders an `<Outlet />`. */
|
|
23
|
+
settings?: RouteComponent;
|
|
24
|
+
/** Connect's own settings tabs; one left out is not listed. */
|
|
25
|
+
settingsTabs?: Partial<Record<CoreSettingsTabId, RouteComponent>>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type CoreSettingsTabId =
|
|
29
|
+
| "ai-assistant"
|
|
30
|
+
| "package-manager"
|
|
31
|
+
| "default-editors"
|
|
32
|
+
| "danger-zone"
|
|
33
|
+
| "about";
|
|
34
|
+
|
|
35
|
+
// Open views stay while a navigation loads; the pending view only after this.
|
|
36
|
+
export const DRIVE_PENDING_MS = 200;
|
|
37
|
+
|
|
38
|
+
// The file routes render the app shell's components, which come in router context.
|
|
39
|
+
function useShellComponents(): Partial<ConnectRouteComponents> {
|
|
40
|
+
return useRouter().options.context.components ?? {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function RootView() {
|
|
44
|
+
const { root: Root = Outlet } = useShellComponents();
|
|
45
|
+
return (
|
|
46
|
+
<>
|
|
47
|
+
{/* The matched routes' head: the document title. */}
|
|
48
|
+
<HeadContent />
|
|
49
|
+
<Root />
|
|
50
|
+
</>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function AppLayoutView() {
|
|
55
|
+
const { app: AppLayout = Outlet } = useShellComponents();
|
|
56
|
+
return <AppLayout />;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function ContentView() {
|
|
60
|
+
const { content: Content = Outlet } = useShellComponents();
|
|
61
|
+
return <Content />;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function NotFoundView() {
|
|
65
|
+
const { notFound: NotFound } = useShellComponents();
|
|
66
|
+
return NotFound ? <NotFound /> : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function DrivePendingView() {
|
|
70
|
+
const { drivePending: DrivePending } = useShellComponents();
|
|
71
|
+
return DrivePending ? <DrivePending /> : null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function DriveNotFoundView({ driveSlug }: { driveSlug: string }) {
|
|
75
|
+
const { driveNotFound: DriveNotFound, notFound: NotFound } =
|
|
76
|
+
useShellComponents();
|
|
77
|
+
if (DriveNotFound) return <DriveNotFound driveSlug={driveSlug} />;
|
|
78
|
+
return NotFound ? <NotFound /> : null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function SettingsView() {
|
|
82
|
+
const { settings: Settings = Outlet } = useShellComponents();
|
|
83
|
+
return <Settings />;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A core settings tab's view: the shell's component for `id`. */
|
|
87
|
+
export function shellSettingsTab(id: CoreSettingsTabId) {
|
|
88
|
+
return function SettingsTabView() {
|
|
89
|
+
const Tab = useShellComponents().settingsTabs?.[id];
|
|
90
|
+
return Tab ? <Tab /> : null;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** A core tab is listed only when the shell provides it. */
|
|
95
|
+
export function shellProvidesTab(id: CoreSettingsTabId) {
|
|
96
|
+
return (context: { components?: ConnectRouteComponents }) =>
|
|
97
|
+
!!context.components?.settingsTabs?.[id];
|
|
98
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Connect's route tree: file routes under src/routes, generated by the router plugin.
|
|
2
|
+
import type { AnyRoute } from "@tanstack/react-router";
|
|
3
|
+
// A project build with its own routes aliases this to its generated tree.
|
|
4
|
+
import type { FileRoutesById } from "@powerhousedao/connect/route-tree";
|
|
5
|
+
import { routeTree } from "@powerhousedao/connect/route-tree";
|
|
6
|
+
import type { ConnectRouteComponents } from "./route-components.js";
|
|
7
|
+
|
|
8
|
+
export { DRIVE_PENDING_MS } from "./route-components.js";
|
|
9
|
+
export type { ConnectRouteComponents } from "./route-components.js";
|
|
10
|
+
|
|
11
|
+
/** The home route's id; a tree change that moves it is a type error here. */
|
|
12
|
+
export const HOME_ROUTE_ID = "/_app/_content/" satisfies keyof FileRoutesById;
|
|
13
|
+
/** The sidebar layout's id; a project's _app/ routes nest in it. */
|
|
14
|
+
export const APP_ROUTE_ID = "/_app";
|
|
15
|
+
const CONTENT_ROUTE_ID = "/_app/_content";
|
|
16
|
+
const DRIVE_PATH = "/d/$driveSlug/{-$nodeSlug}";
|
|
17
|
+
const SETTINGS_ROUTE_ID = "/_app/settings";
|
|
18
|
+
|
|
19
|
+
type RouteOptions = { id?: string; path?: string };
|
|
20
|
+
|
|
21
|
+
// Generated routes carry their full id only once a router initialises them.
|
|
22
|
+
function findChild(parent: AnyRoute, idOrPath: string) {
|
|
23
|
+
const children = (parent.children ?? []) as AnyRoute[];
|
|
24
|
+
const child = children.find((route) => {
|
|
25
|
+
const options = route.options as RouteOptions;
|
|
26
|
+
return options.id === idOrPath || options.path === idOrPath;
|
|
27
|
+
});
|
|
28
|
+
if (!child) throw new Error(`Connect's route tree lacks ${idOrPath}`);
|
|
29
|
+
return child;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Named, so declarations reach the tree through the specifier a project aliases;
|
|
33
|
+
// inferred types would point at Connect's own generated file.
|
|
34
|
+
export type ConnectRootRoute = typeof routeTree;
|
|
35
|
+
export type ConnectRoutes = {
|
|
36
|
+
routeTree: ConnectRootRoute;
|
|
37
|
+
rootRoute: ConnectRootRoute;
|
|
38
|
+
appRoute: FileRoutesById[typeof APP_ROUTE_ID];
|
|
39
|
+
contentRoute: FileRoutesById[typeof CONTENT_ROUTE_ID];
|
|
40
|
+
homeRoute: FileRoutesById[typeof HOME_ROUTE_ID];
|
|
41
|
+
driveRoute: FileRoutesById[`${typeof CONTENT_ROUTE_ID}${typeof DRIVE_PATH}`];
|
|
42
|
+
settingsRoute: FileRoutesById[typeof SETTINGS_ROUTE_ID];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Connect's routes in the generated tree; deployment routes attach to these. */
|
|
46
|
+
export function connectRoutes(): ConnectRoutes {
|
|
47
|
+
const appRoute = findChild(routeTree, APP_ROUTE_ID);
|
|
48
|
+
const contentRoute = findChild(appRoute, "/_content");
|
|
49
|
+
return {
|
|
50
|
+
routeTree,
|
|
51
|
+
rootRoute: routeTree,
|
|
52
|
+
appRoute: appRoute as ConnectRoutes["appRoute"],
|
|
53
|
+
contentRoute: contentRoute as ConnectRoutes["contentRoute"],
|
|
54
|
+
homeRoute: findChild(contentRoute, "/") as ConnectRoutes["homeRoute"],
|
|
55
|
+
driveRoute: findChild(
|
|
56
|
+
contentRoute,
|
|
57
|
+
DRIVE_PATH,
|
|
58
|
+
) as ConnectRoutes["driveRoute"],
|
|
59
|
+
settingsRoute: findChild(
|
|
60
|
+
appRoute,
|
|
61
|
+
"/settings",
|
|
62
|
+
) as ConnectRoutes["settingsRoute"],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Code routes, e.g. `createRoute({ getParentRoute: () => rootRoute })`, join
|
|
67
|
+
* their parent's file routes; an embedding app without the router plugin adds routes so. */
|
|
68
|
+
export function addConnectRoutes(routes: readonly AnyRoute[]) {
|
|
69
|
+
for (const route of routes) {
|
|
70
|
+
const parent = route.options.getParentRoute() as AnyRoute | undefined;
|
|
71
|
+
if (!parent) throw new Error("A Connect route needs getParentRoute");
|
|
72
|
+
const children = (parent.children ?? []) as AnyRoute[];
|
|
73
|
+
if (!children.includes(route)) parent.addChildren([...children, route]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The route tree; components reach its routes through router context. */
|
|
78
|
+
export function createConnectRouteTree(
|
|
79
|
+
_components?: ConnectRouteComponents,
|
|
80
|
+
): ConnectRouteTree {
|
|
81
|
+
const { homeRoute, driveRoute } = connectRoutes();
|
|
82
|
+
return { routeTree, homeRoute, driveRoute };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type ConnectRouteTree = Pick<
|
|
86
|
+
ConnectRoutes,
|
|
87
|
+
"routeTree" | "homeRoute" | "driveRoute"
|
|
88
|
+
>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyRouter,
|
|
3
|
+
ParsedLocation,
|
|
4
|
+
RouterHistory,
|
|
5
|
+
} from "@tanstack/react-router";
|
|
6
|
+
|
|
7
|
+
type ScrollRouter = Pick<AnyRouter, "subscribe" | "_scroll" | "options"> & {
|
|
8
|
+
history: RouterHistory;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const TRAVERSALS = new Set(["BACK", "FORWARD", "GO"]);
|
|
12
|
+
const traversals = new WeakMap<object, { traversal: boolean }>();
|
|
13
|
+
|
|
14
|
+
/** The router's `scrollRestoration`: on for back/forward only; other
|
|
15
|
+
* navigations reset the content view in `bindConnectScroll`. */
|
|
16
|
+
export function connectScrollRestoration() {
|
|
17
|
+
// The first load restores a reloaded page's scroll.
|
|
18
|
+
const state = { traversal: true };
|
|
19
|
+
const restore = ({ location }: { location: ParsedLocation }) =>
|
|
20
|
+
state.traversal || !!location.hash;
|
|
21
|
+
traversals.set(restore, state);
|
|
22
|
+
return restore;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Tracks history actions, and resets a scrolled content view on new views. */
|
|
26
|
+
export function bindConnectScroll(router: ScrollRouter, contentViewId: string) {
|
|
27
|
+
const state = traversals.get(router.options.scrollRestoration as object);
|
|
28
|
+
if (!state) return () => {};
|
|
29
|
+
const unsubscribeHistory = router.history.subscribe(({ action }) => {
|
|
30
|
+
state.traversal = TRAVERSALS.has(action.type);
|
|
31
|
+
});
|
|
32
|
+
if (typeof document === "undefined") return unsubscribeHistory;
|
|
33
|
+
|
|
34
|
+
// Read in the scroll event, where layout is clean, not at navigation.
|
|
35
|
+
let scrolledView: Element | undefined;
|
|
36
|
+
let windowScrolled = false;
|
|
37
|
+
const onScroll = (event: Event) => {
|
|
38
|
+
const target = event.target;
|
|
39
|
+
if (target === document) {
|
|
40
|
+
windowScrolled = window.scrollY > 0 || window.scrollX > 0;
|
|
41
|
+
} else if (target instanceof Element && target.id === contentViewId) {
|
|
42
|
+
scrolledView = target.scrollTop > 0 ? target : undefined;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
document.addEventListener("scroll", onScroll, {
|
|
46
|
+
capture: true,
|
|
47
|
+
passive: true,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
let resetScroll = true;
|
|
51
|
+
const unsubscribes = [
|
|
52
|
+
unsubscribeHistory,
|
|
53
|
+
// The navigation's `resetScroll`, before the router clears it on render.
|
|
54
|
+
router.subscribe("onBeforeRouteMount", () => {
|
|
55
|
+
resetScroll = router._scroll.n;
|
|
56
|
+
}),
|
|
57
|
+
router.subscribe("onRendered", ({ toLocation }) => {
|
|
58
|
+
if (state.traversal || toLocation.hash || !resetScroll) return;
|
|
59
|
+
if (scrolledView?.isConnected) scrolledView.scrollTo(0, 0);
|
|
60
|
+
if (windowScrolled) window.scrollTo(0, 0);
|
|
61
|
+
scrolledView = undefined;
|
|
62
|
+
windowScrolled = false;
|
|
63
|
+
}),
|
|
64
|
+
];
|
|
65
|
+
return () => {
|
|
66
|
+
document.removeEventListener("scroll", onScroll, { capture: true });
|
|
67
|
+
for (const unsubscribe of unsubscribes) unsubscribe();
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FEATURE_FLAG_PARAM_PREFIX,
|
|
3
|
+
GLOBAL_SEARCH_PARAMS,
|
|
4
|
+
} from "@powerhousedao/reactor-browser";
|
|
5
|
+
import type { SearchMiddleware } from "@tanstack/react-router";
|
|
6
|
+
import { retainSearchParams } from "@tanstack/react-router";
|
|
7
|
+
|
|
8
|
+
// Shared with reactor-browser's fallback navigation.
|
|
9
|
+
export { FEATURE_FLAG_PARAM_PREFIX, GLOBAL_SEARCH_PARAMS };
|
|
10
|
+
|
|
11
|
+
/** Connect's query params: plain strings, as in the URL. */
|
|
12
|
+
export type ConnectSearch = Record<string, string | undefined>;
|
|
13
|
+
|
|
14
|
+
const retainFeatureFlags: SearchMiddleware<ConnectSearch> = ({
|
|
15
|
+
search,
|
|
16
|
+
next,
|
|
17
|
+
}) => {
|
|
18
|
+
const result = { ...next(search) };
|
|
19
|
+
for (const [key, value] of Object.entries(search)) {
|
|
20
|
+
if (key.startsWith(FEATURE_FLAG_PARAM_PREFIX) && !(key in result)) {
|
|
21
|
+
result[key] = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** The root route's middlewares; they apply to every navigation and redirect. */
|
|
28
|
+
export const connectSearchMiddlewares: SearchMiddleware<ConnectSearch>[] = [
|
|
29
|
+
retainSearchParams<ConnectSearch>([...GLOBAL_SEARCH_PARAMS]),
|
|
30
|
+
retainFeatureFlags,
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
/** Lets every param through; routes add none of their own. */
|
|
34
|
+
export function validateConnectSearch(
|
|
35
|
+
search: Record<string, unknown>,
|
|
36
|
+
): ConnectSearch {
|
|
37
|
+
return search as ConnectSearch;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Parses a query string into plain string values, unlike the JSON default. */
|
|
41
|
+
export function parseConnectSearch(searchStr: string): ConnectSearch {
|
|
42
|
+
return Object.fromEntries(new URLSearchParams(searchStr));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Writes plain `key=value` pairs, so other readers of the URL see strings. */
|
|
46
|
+
export function stringifyConnectSearch(search: Record<string, unknown>) {
|
|
47
|
+
const params = new URLSearchParams();
|
|
48
|
+
for (const [key, value] of Object.entries(search)) {
|
|
49
|
+
if (value === undefined || value === null) continue;
|
|
50
|
+
params.set(key, typeof value === "string" ? value : JSON.stringify(value));
|
|
51
|
+
}
|
|
52
|
+
const searchStr = params.toString();
|
|
53
|
+
return searchStr ? `?${searchStr}` : "";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The defined values of `search`, for callers that take plain records. */
|
|
57
|
+
export function definedSearch(search: object): Record<string, string> {
|
|
58
|
+
const record: Record<string, string> = {};
|
|
59
|
+
for (const [key, value] of Object.entries(search)) {
|
|
60
|
+
if (typeof value === "string") record[key] = value;
|
|
61
|
+
else if (value !== undefined && value !== null) {
|
|
62
|
+
record[key] = JSON.stringify(value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return record;
|
|
66
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// The settings page: its tabs are the /settings route's children with `staticData.settings`.
|
|
2
|
+
import {
|
|
3
|
+
OPENED_FROM_STATE_KEY,
|
|
4
|
+
SETTINGS_PATH,
|
|
5
|
+
} from "@powerhousedao/reactor-browser";
|
|
6
|
+
import type {
|
|
7
|
+
AnyRoute,
|
|
8
|
+
AnyRouter,
|
|
9
|
+
HistoryState,
|
|
10
|
+
MakeRouteMatchUnion,
|
|
11
|
+
} from "@tanstack/react-router";
|
|
12
|
+
import { useRouter } from "@tanstack/react-router";
|
|
13
|
+
import type { ComponentType } from "react";
|
|
14
|
+
import { useMemo } from "react";
|
|
15
|
+
import type { ConnectRouterContext } from "./drive-route-loader.js";
|
|
16
|
+
import { appTitle } from "./titles.js";
|
|
17
|
+
|
|
18
|
+
/** A settings tab, as a child route of /settings declares it in `staticData`. */
|
|
19
|
+
export type ConnectSettingsTab = {
|
|
20
|
+
label: string;
|
|
21
|
+
/** Ascending; Connect's own tabs use multiples of 10. */
|
|
22
|
+
order: number;
|
|
23
|
+
icon?: ComponentType<{ size?: number; className?: string }>;
|
|
24
|
+
/** Marks the tab as destructive, e.g. the danger zone. */
|
|
25
|
+
destructive?: boolean;
|
|
26
|
+
/** Hidden, and redirected away from, when this returns false. */
|
|
27
|
+
enabled?: (context: ConnectRouterContext) => boolean;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
declare module "@tanstack/react-router" {
|
|
31
|
+
interface StaticDataRouteOption {
|
|
32
|
+
settings?: ConnectSettingsTab;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The settings layout route's id. */
|
|
37
|
+
export const SETTINGS_ROUTE_ID = `/_app${SETTINGS_PATH}`;
|
|
38
|
+
|
|
39
|
+
/** A listed tab: its id is its path below /settings. */
|
|
40
|
+
export type SettingsTabEntry = ConnectSettingsTab & {
|
|
41
|
+
id: string;
|
|
42
|
+
routeId: string;
|
|
43
|
+
to: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** The enabled tabs below `settingsRoute`, in order. */
|
|
47
|
+
export function settingsTabsOf(
|
|
48
|
+
settingsRoute: AnyRoute,
|
|
49
|
+
context: ConnectRouterContext,
|
|
50
|
+
): SettingsTabEntry[] {
|
|
51
|
+
const children = (settingsRoute.children ?? []) as AnyRoute[];
|
|
52
|
+
const prefix = `${settingsRoute.fullPath}/`;
|
|
53
|
+
return children
|
|
54
|
+
.flatMap((route) => {
|
|
55
|
+
const tab = (
|
|
56
|
+
route.options as { staticData?: { settings?: ConnectSettingsTab } }
|
|
57
|
+
).staticData?.settings;
|
|
58
|
+
if (!tab || tab.enabled?.(context) === false) return [];
|
|
59
|
+
const { id: routeId, fullPath } = route as {
|
|
60
|
+
id: string;
|
|
61
|
+
fullPath: string;
|
|
62
|
+
};
|
|
63
|
+
const to = fullPath.replace(/\/$/, "");
|
|
64
|
+
return [{ ...tab, id: to.slice(prefix.length), routeId, to }];
|
|
65
|
+
})
|
|
66
|
+
.sort((a, b) => a.order - b.order || a.label.localeCompare(b.label));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The settings tabs of `router`'s tree; empty without a settings route. */
|
|
70
|
+
export function settingsTabs(router: AnyRouter): SettingsTabEntry[] {
|
|
71
|
+
const settingsRoute = router.routesById[SETTINGS_ROUTE_ID] as
|
|
72
|
+
| AnyRoute
|
|
73
|
+
| undefined;
|
|
74
|
+
if (!settingsRoute) return [];
|
|
75
|
+
return settingsTabsOf(
|
|
76
|
+
settingsRoute,
|
|
77
|
+
router.options.context as ConnectRouterContext,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function useSettingsTabs() {
|
|
82
|
+
const router = useRouter();
|
|
83
|
+
return useMemo(() => settingsTabs(router), [router]);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Whether `matches` show a tab that may stay: not bare /settings, not a disabled tab. */
|
|
87
|
+
export function showsSettingsTab(
|
|
88
|
+
matches: readonly MakeRouteMatchUnion[],
|
|
89
|
+
context: ConnectRouterContext,
|
|
90
|
+
) {
|
|
91
|
+
const leaf = matches.at(-1);
|
|
92
|
+
if (!leaf || leaf.routeId === SETTINGS_ROUTE_ID) return false;
|
|
93
|
+
return leaf.staticData.settings?.enabled?.(context) !== false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** `Settings · <tab> · <app>`. */
|
|
97
|
+
export function settingsTitle(tabLabel: string | undefined, appName?: string) {
|
|
98
|
+
return ["Settings", tabLabel, appTitle(appName)].filter(Boolean).join(" · ");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Makes closing settings go home, not back to an entry that may be gone,
|
|
102
|
+
* e.g. a deleted drive. */
|
|
103
|
+
export function useForgetSettingsOpenedFrom() {
|
|
104
|
+
const router = useRouter();
|
|
105
|
+
return () =>
|
|
106
|
+
router.navigate({
|
|
107
|
+
to: ".",
|
|
108
|
+
search: true,
|
|
109
|
+
replace: true,
|
|
110
|
+
resetScroll: false,
|
|
111
|
+
state: (prev) =>
|
|
112
|
+
({ ...prev, [OPENED_FROM_STATE_KEY]: undefined }) as HistoryState,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** History state that keeps where the settings page was opened from. */
|
|
117
|
+
export function keepOpenedFrom(state: object) {
|
|
118
|
+
const from: unknown = Reflect.get(state, OPENED_FROM_STATE_KEY);
|
|
119
|
+
return { [OPENED_FROM_STATE_KEY]: from } as unknown as HistoryState;
|
|
120
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// What routes tell the sidebar layout: nav items and whether to show the sidebar.
|
|
2
|
+
import type { AnyRoute, AnyRouter } from "@tanstack/react-router";
|
|
3
|
+
import { useMatches, useRouter } from "@tanstack/react-router";
|
|
4
|
+
import type { ComponentType } from "react";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
|
|
7
|
+
/** A sidebar link to the route that declares it in `staticData.nav`. */
|
|
8
|
+
export type ConnectNavItem = {
|
|
9
|
+
label: string;
|
|
10
|
+
icon?: ComponentType<{ size?: number; className?: string }>;
|
|
11
|
+
/** Ascending, after the drives. */
|
|
12
|
+
order: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** "hidden" drops the sidebar; "collapsed" keeps only its header and footer. */
|
|
16
|
+
export type SidebarMode = "hidden" | "collapsed";
|
|
17
|
+
|
|
18
|
+
declare module "@tanstack/react-router" {
|
|
19
|
+
interface StaticDataRouteOption {
|
|
20
|
+
nav?: ConnectNavItem;
|
|
21
|
+
sidebar?: SidebarMode;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type NavRouteEntry = ConnectNavItem & { routeId: string; to: string };
|
|
26
|
+
|
|
27
|
+
/** The routes with `staticData.nav`, in order; routes with params can't be listed. */
|
|
28
|
+
export function navRoutes(router: AnyRouter): NavRouteEntry[] {
|
|
29
|
+
return Object.values(router.routesById as Record<string, AnyRoute>)
|
|
30
|
+
.flatMap((route) => {
|
|
31
|
+
const nav = (route.options as { staticData?: { nav?: ConnectNavItem } })
|
|
32
|
+
.staticData?.nav;
|
|
33
|
+
const { id: routeId, fullPath } = route as {
|
|
34
|
+
id: string;
|
|
35
|
+
fullPath: string;
|
|
36
|
+
};
|
|
37
|
+
if (!nav || fullPath.includes("$")) return [];
|
|
38
|
+
return [{ ...nav, routeId, to: fullPath.replace(/(.)\/$/, "$1") }];
|
|
39
|
+
})
|
|
40
|
+
.sort((a, b) => a.order - b.order || a.label.localeCompare(b.label));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function useNavRoutes() {
|
|
44
|
+
const router = useRouter();
|
|
45
|
+
return useMemo(() => navRoutes(router), [router]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The deepest match's `staticData.sidebar`, if any declares one. */
|
|
49
|
+
export function useSidebarMode(): SidebarMode | undefined {
|
|
50
|
+
return useMatches({
|
|
51
|
+
select: (matches) =>
|
|
52
|
+
matches.findLast((match) => match.staticData.sidebar !== undefined)
|
|
53
|
+
?.staticData.sidebar,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PHStore } from "@powerhousedao/reactor-browser";
|
|
2
|
+
import { driveCreateDocument } from "@powerhousedao/shared/document-drive";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { driveTitle } from "./titles.js";
|
|
5
|
+
|
|
6
|
+
function storeWith(globalName: string, headerName: string) {
|
|
7
|
+
const drive = driveCreateDocument({
|
|
8
|
+
global: { name: globalName, icon: null, nodes: [] },
|
|
9
|
+
});
|
|
10
|
+
drive.header.name = headerName;
|
|
11
|
+
return { store: { drives: [drive] } as PHStore, driveId: drive.header.id };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe("driveTitle", () => {
|
|
15
|
+
it("names a drive added from Connect, whose header has no name", () => {
|
|
16
|
+
const { store, driveId } = storeWith("Local", "");
|
|
17
|
+
expect(driveTitle(store, { driveId })).toBe("Local · Connect");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("names a renamed drive by its header", () => {
|
|
21
|
+
const { store, driveId } = storeWith("Old", "Renamed");
|
|
22
|
+
expect(driveTitle(store, { driveId }, "App")).toBe("Renamed · App");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Document titles for Connect's routes; route heads set them through <HeadContent />.
|
|
2
|
+
import type { PHStore } from "@powerhousedao/reactor-browser";
|
|
3
|
+
import { getDriveName } from "@powerhousedao/reactor-browser";
|
|
4
|
+
import type { DriveRouteData } from "./drive-route-loader.js";
|
|
5
|
+
|
|
6
|
+
const DEFAULT_APP_NAME = "Connect";
|
|
7
|
+
|
|
8
|
+
/** The configured app name, else "Connect". */
|
|
9
|
+
export function appTitle(appName?: string) {
|
|
10
|
+
return appName || DEFAULT_APP_NAME;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** `Not found · <app>`. */
|
|
14
|
+
export function notFoundTitle(appName?: string) {
|
|
15
|
+
return `Not found · ${appTitle(appName)}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** `<node> · <drive> · <app>`, from the store so renames show. */
|
|
19
|
+
export function driveTitle(
|
|
20
|
+
store: PHStore,
|
|
21
|
+
data: DriveRouteData | undefined,
|
|
22
|
+
appName?: string,
|
|
23
|
+
) {
|
|
24
|
+
const drive = data && store.drives?.find((d) => d.header.id === data.driveId);
|
|
25
|
+
if (!drive) return appTitle(appName);
|
|
26
|
+
const node = data.nodeId
|
|
27
|
+
? drive.state.global.nodes.find((n) => n.id === data.nodeId)
|
|
28
|
+
: undefined;
|
|
29
|
+
return [node?.name, getDriveName(drive)]
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.concat(appTitle(appName))
|
|
32
|
+
.join(" · ");
|
|
33
|
+
}
|