@powerhousedao/connect 6.2.3-dev.66 → 6.2.3-dev.67
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/CUSTOMIZING.md +77 -0
- package/README.md +18 -91
- package/RUNTIME-CONFIG.md +472 -0
- package/dist/{AddDriveModal-D_3jDwjp.js → AddDriveModal-BjgmiHJr.js} +6 -6
- package/dist/AddDriveModal-BjgmiHJr.js.map +1 -0
- package/dist/{ClearStorageModal-zZ8XzwmR.js → ClearStorageModal-_03VgDb5.js} +6 -6
- package/dist/ClearStorageModal-_03VgDb5.js.map +1 -0
- package/dist/{ConfirmDocumentUpgradeModal-CrU2Z1CL.js → ConfirmDocumentUpgradeModal-CoixS60F.js} +5 -5
- package/dist/ConfirmDocumentUpgradeModal-CoixS60F.js.map +1 -0
- package/dist/{CookiesPolicyModal-DQwsgDI9.js → CookiesPolicyModal-BpFjYc7T.js} +4 -4
- package/dist/{CookiesPolicyModal-DQwsgDI9.js.map → CookiesPolicyModal-BpFjYc7T.js.map} +1 -1
- package/dist/{CreateDocumentModal-Cf1APibL.js → CreateDocumentModal-B-cXzeOA.js} +10 -10
- package/dist/CreateDocumentModal-B-cXzeOA.js.map +1 -0
- package/dist/{DebugSettingsModal-DIc5C2lI.js → DebugSettingsModal-CGScJ_r2.js} +8 -8
- package/dist/DebugSettingsModal-CGScJ_r2.js.map +1 -0
- package/dist/{DeleteDriveModal-lE9eCBua.js → DeleteDriveModal-1pAIayG_.js} +5 -5
- package/dist/DeleteDriveModal-1pAIayG_.js.map +1 -0
- package/dist/{DeleteItemModal-BFgcGsm3.js → DeleteItemModal-BUpqmFxS.js} +5 -5
- package/dist/DeleteItemModal-BUpqmFxS.js.map +1 -0
- package/dist/{DisclaimerModal-CF6JkIIu.js → DisclaimerModal-TIJXRYLF.js} +5 -5
- package/dist/DisclaimerModal-TIJXRYLF.js.map +1 -0
- package/dist/{DocumentVersionUnsupportedModal-Cm9Jb9W7.js → DocumentVersionUnsupportedModal-DH9Zzsyw.js} +5 -5
- package/dist/DocumentVersionUnsupportedModal-DH9Zzsyw.js.map +1 -0
- package/dist/{DownloadDocumentWithErrorsModal-CShKhfEQ.js → DownloadDocumentWithErrorsModal-Beh-xw8B.js} +5 -5
- package/dist/DownloadDocumentWithErrorsModal-Beh-xw8B.js.map +1 -0
- package/dist/{DriveAuthRequiredModal-CMwPUyZf.js → DriveAuthRequiredModal-XTcoJKvj.js} +6 -6
- package/dist/DriveAuthRequiredModal-XTcoJKvj.js.map +1 -0
- package/dist/{DriveSettingsModal-BSImj4BH.js → DriveSettingsModal-DZKawN7w.js} +5 -5
- package/dist/DriveSettingsModal-DZKawN7w.js.map +1 -0
- package/dist/{InspectorModal-Dr8-gj6u.js → InspectorModal-DA_TGmM6.js} +16 -16
- package/dist/InspectorModal-DA_TGmM6.js.map +1 -0
- package/dist/{LoginModal-DT_05uva.js → LoginModal-O06ZvWFI.js} +6 -6
- package/dist/LoginModal-O06ZvWFI.js.map +1 -0
- package/dist/{OpenFileDocumentsModal-X9GnX2Bk.js → OpenFileDocumentsModal-BNHD0vg9.js} +6 -6
- package/dist/OpenFileDocumentsModal-BNHD0vg9.js.map +1 -0
- package/dist/{UpgradeDriveModal-DvM-PNWe.js → UpgradeDriveModal-CCWKp5yn.js} +5 -5
- package/dist/UpgradeDriveModal-CCWKp5yn.js.map +1 -0
- package/dist/{app-loader-DrViXipO.js → app-loader-CEN_4I3I.js} +149 -196
- package/dist/app-loader-CEN_4I3I.js.map +1 -0
- package/dist/app-loader-Cj2p8L1I.js +4 -0
- package/dist/{app-skeleton-gzg8cRzm.js → app-skeleton-BFjvlTWd.js} +11 -11
- package/dist/app-skeleton-BFjvlTWd.js.map +1 -0
- package/dist/{app-skeleton-DYLZ7npI.js → app-skeleton-DFg65Rxa.js} +3 -3
- package/dist/{boot-CC_DgQKX.js → boot-JTGLJtmJ.js} +6 -6
- package/dist/boot-JTGLJtmJ.js.map +1 -0
- package/dist/{build-info-DMrToXJe.js → build-info-DkY9PU7c.js} +5 -5
- package/dist/{build-info-DMrToXJe.js.map → build-info-DkY9PU7c.js.map} +1 -1
- package/dist/{components-CjF9XjxP.js → components-2wvJ3_Ho.js} +11 -10
- package/dist/{components-CjF9XjxP.js.map → components-2wvJ3_Ho.js.map} +1 -1
- package/dist/{connect.config-uZF-gnvV.js → connect.config-D1pGNmaF.js} +4 -4
- package/dist/connect.config-D1pGNmaF.js.map +1 -0
- package/dist/{connection-state-C_477Kr_.js → connection-state-B6fleM37.js} +6 -6
- package/dist/connection-state-B6fleM37.js.map +1 -0
- package/dist/{cookie-banner-HPgyuHM5.js → cookie-banner-CAvd3PC3.js} +6 -6
- package/dist/{cookie-banner-HPgyuHM5.js.map → cookie-banner-CAvd3PC3.js.map} +1 -1
- package/dist/document-editor-container-BnEjlmaN.js +307 -0
- package/dist/document-editor-container-BnEjlmaN.js.map +1 -0
- package/dist/document-editor-container-kgS38mkb.js +4 -0
- package/dist/error-boundary-BsUBww61.js +155 -0
- package/dist/error-boundary-BsUBww61.js.map +1 -0
- package/dist/generic.d.ts +116 -0
- package/dist/generic.d.ts.map +1 -0
- package/dist/generic.js +31 -0
- package/dist/generic.js.map +1 -0
- package/dist/{i18n-CTgT1HG-.js → i18n-D9WYPgk9.js} +4 -4
- package/dist/{i18n-CTgT1HG-.js.map → i18n-D9WYPgk9.js.map} +1 -1
- package/dist/index-B4g8swZG.d.ts +4 -0
- package/dist/layout-BOX6fL5v.js +5 -0
- package/dist/layout.d.ts +2 -28
- package/dist/layout.js +4 -6
- package/dist/{load--K_UgzUy.js → load-CCCHqC0d.js} +11 -11
- package/dist/{load--K_UgzUy.js.map → load-CCCHqC0d.js.map} +1 -1
- package/dist/load-runtime-config-Dhy-b5wT.js +14 -0
- package/dist/load-runtime-config-Dhy-b5wT.js.map +1 -0
- package/dist/main.js +2 -2
- package/dist/{open-file-uploads-BcyWmUZn.js → open-file-uploads-B5pr1sA2.js} +4 -4
- package/dist/{open-file-uploads-BcyWmUZn.js.map → open-file-uploads-B5pr1sA2.js.map} +1 -1
- package/dist/{package-manager-BkFRzovd.js → package-manager-x_fK8Hzm.js} +92 -60
- package/dist/package-manager-x_fK8Hzm.js.map +1 -0
- package/dist/{pglite-seed-BsEPByVM.js → pglite-seed-eGzXMld2.js} +4 -4
- package/dist/{pglite-seed-BsEPByVM.js.map → pglite-seed-eGzXMld2.js.map} +1 -1
- package/dist/{plugin-host--lBWChr9.js → plugins-B9VBgzio.js} +75 -83
- package/dist/plugins-B9VBgzio.js.map +1 -0
- package/dist/{preferences-store-DANUajdg.js → preferences-store-CSqauT9V.js} +5 -5
- package/dist/preferences-store-CSqauT9V.js.map +1 -0
- package/dist/prerender.d.ts +38 -0
- package/dist/prerender.d.ts.map +1 -0
- package/dist/prerender.js +177 -0
- package/dist/prerender.js.map +1 -0
- package/dist/{prerendered-shell-DxCUDEXL.js → prerendered-shell-peKE7AqI.js} +10 -4
- package/dist/prerendered-shell-peKE7AqI.js.map +1 -0
- package/dist/{reactor-5nod7BfF.js → reactor-BmI-D8O-.js} +25 -156
- package/dist/reactor-BmI-D8O-.js.map +1 -0
- package/dist/{registerServiceWorker-CkVxA2KC.js → registerServiceWorker-APlHkrmH.js} +4 -4
- package/dist/{registerServiceWorker-CkVxA2KC.js.map → registerServiceWorker-APlHkrmH.js.map} +1 -1
- package/dist/root-B1Pq9x6S.js +24 -0
- package/dist/root-B1Pq9x6S.js.map +1 -0
- package/dist/route-tree.d.ts +147 -156
- package/dist/route-tree.d.ts.map +1 -1
- package/dist/route-tree.js +93 -169
- package/dist/route-tree.js.map +1 -1
- package/dist/route-views-BF0p-4Fi.js +60 -0
- package/dist/route-views-BF0p-4Fi.js.map +1 -0
- package/dist/route-views-CTARvT5N.js +55 -0
- package/dist/route-views-CTARvT5N.js.map +1 -0
- package/dist/route-views-D8I-1PWU.js +4 -0
- package/dist/route-views.d.ts +7 -0
- package/dist/route-views.d.ts.map +1 -0
- package/dist/route-views.js +4 -0
- package/dist/router-BguOMBUh.js +4 -0
- package/dist/router-L9X9U-97.js +46 -0
- package/dist/router-L9X9U-97.js.map +1 -0
- package/dist/router.d.ts +1 -3
- package/dist/router.js +3 -7
- package/dist/sentry-Cuc_Nbba.js +22 -0
- package/dist/sentry-Cuc_Nbba.js.map +1 -0
- package/dist/{settings-DkLhRfEI.js → settings-DjQfTrBe.js} +488 -22
- package/dist/settings-DjQfTrBe.js.map +1 -0
- package/dist/settings-tabs-iTlo2pYz.js +365 -0
- package/dist/settings-tabs-iTlo2pYz.js.map +1 -0
- package/dist/shell-core-head.html +2 -0
- package/dist/shell-core.html +1 -0
- package/dist/shell-head.html +2 -1
- package/dist/shell-plugins.json +1 -0
- package/dist/shell.html +1 -1
- package/dist/start-connect.d.ts +5 -9
- package/dist/start-connect.d.ts.map +1 -1
- package/dist/start-connect.js +5 -6
- package/dist/start-connect.js.map +1 -1
- package/dist/style.css +3127 -4014
- package/dist/ui-b6sMhi5V.js +66 -0
- package/dist/ui-b6sMhi5V.js.map +1 -0
- package/dist/{use-renown-login-BzOSQETV.js → use-renown-login-dPpDOYq5.js} +4 -4
- package/dist/use-renown-login-dPpDOYq5.js.map +1 -0
- package/docs/customizing/data-and-navigation.md +177 -0
- package/docs/customizing/hosts-and-plugins.md +65 -0
- package/docs/customizing/layout.md +149 -0
- package/docs/customizing/modals.md +78 -0
- package/docs/customizing/overrides.md +113 -0
- package/docs/customizing/packages.md +38 -0
- package/docs/customizing/pages.md +136 -0
- package/docs/customizing/styles-and-branding.md +41 -0
- package/docs/customizing/types-and-troubleshooting.md +44 -0
- package/package.json +41 -18
- package/scripts/prerender-shell.ts +35 -84
- package/skills/customize-connect/SKILL.md +74 -0
- package/src/route-tree.ts +3 -0
- package/src/routeTree.gen.ts +134 -192
- package/src/router/index.ts +2 -51
- package/src/router/register.ts +1 -1
- package/src/routes/__root.tsx +8 -24
- package/src/routes/_app/$.tsx +13 -0
- package/src/routes/_app/d/$driveSlug/{-$nodeSlug}.tsx +13 -0
- package/src/routes/_app/d/$driveSlug.tsx +13 -0
- package/src/routes/_app/index.tsx +13 -0
- package/src/routes/_app/settings/appearance.tsx +13 -0
- package/src/routes/_app/settings/packages.tsx +13 -0
- package/src/routes/_app/settings.tsx +13 -0
- package/src/routes/_app.tsx +13 -0
- package/style.css +5 -22
- package/tailwind.css +12 -0
- package/dist/AddDriveModal-D_3jDwjp.js.map +0 -1
- package/dist/ClearStorageModal-zZ8XzwmR.js.map +0 -1
- package/dist/ConfirmDocumentUpgradeModal-CrU2Z1CL.js.map +0 -1
- package/dist/CreateDocumentModal-Cf1APibL.js.map +0 -1
- package/dist/DebugSettingsModal-DIc5C2lI.js.map +0 -1
- package/dist/DeleteDriveModal-lE9eCBua.js.map +0 -1
- package/dist/DeleteItemModal-BFgcGsm3.js.map +0 -1
- package/dist/DisclaimerModal-CF6JkIIu.js.map +0 -1
- package/dist/DocumentVersionUnsupportedModal-Cm9Jb9W7.js.map +0 -1
- package/dist/DownloadDocumentWithErrorsModal-CShKhfEQ.js.map +0 -1
- package/dist/DriveAuthRequiredModal-CMwPUyZf.js.map +0 -1
- package/dist/DriveSettingsModal-BSImj4BH.js.map +0 -1
- package/dist/InspectorModal-Dr8-gj6u.js.map +0 -1
- package/dist/LoginModal-DT_05uva.js.map +0 -1
- package/dist/MissingPackageModal-DtISKgub.js +0 -49
- package/dist/MissingPackageModal-DtISKgub.js.map +0 -1
- package/dist/OpenFileDocumentsModal-X9GnX2Bk.js.map +0 -1
- package/dist/UpgradeDriveModal-DvM-PNWe.js.map +0 -1
- package/dist/app-layout-BIq-ZW-6.js +0 -394
- package/dist/app-layout-BIq-ZW-6.js.map +0 -1
- package/dist/app-loader-CWAH-WxW.js +0 -4
- package/dist/app-loader-DrViXipO.js.map +0 -1
- package/dist/app-skeleton-gzg8cRzm.js.map +0 -1
- package/dist/boot-CC_DgQKX.js.map +0 -1
- package/dist/connect-router-KmNBGS0G.js +0 -434
- package/dist/connect-router-KmNBGS0G.js.map +0 -1
- package/dist/connect.config-uZF-gnvV.js.map +0 -1
- package/dist/connection-state-C_477Kr_.js.map +0 -1
- package/dist/index-UrZFqSgm.d.ts +0 -166
- package/dist/index-UrZFqSgm.d.ts.map +0 -1
- package/dist/layout.d.ts.map +0 -1
- package/dist/multi-reactor-fSKpLBjT.js +0 -220
- package/dist/multi-reactor-fSKpLBjT.js.map +0 -1
- package/dist/package-manager-BkFRzovd.js.map +0 -1
- package/dist/plugin-host--lBWChr9.js.map +0 -1
- package/dist/preferences-store-DANUajdg.js.map +0 -1
- package/dist/prerendered-shell-DxCUDEXL.js.map +0 -1
- package/dist/reactor-5nod7BfF.js.map +0 -1
- package/dist/route-components-BkztQruF.js +0 -148
- package/dist/route-components-BkztQruF.js.map +0 -1
- package/dist/router-8RIbbf6v.js +0 -4
- package/dist/router-C37yATTD.js +0 -604
- package/dist/router-C37yATTD.js.map +0 -1
- package/dist/runtime-config-DdN1Frg7.js +0 -34
- package/dist/runtime-config-DdN1Frg7.js.map +0 -1
- package/dist/runtime-flag-B8IYhkz-.js +0 -4
- package/dist/runtime-flag-CT5OKujT.js +0 -45
- package/dist/runtime-flag-CT5OKujT.js.map +0 -1
- package/dist/sentry-CJb7--mu.js +0 -18
- package/dist/sentry-CJb7--mu.js.map +0 -1
- package/dist/settings-CjvK8OKA.js +0 -91
- package/dist/settings-CjvK8OKA.js.map +0 -1
- package/dist/settings-DkLhRfEI.js.map +0 -1
- package/dist/sidebar-BXf8OEwm.d.ts +0 -34
- package/dist/sidebar-BXf8OEwm.d.ts.map +0 -1
- package/dist/sidebar-lAVFRsni.js +0 -31
- package/dist/sidebar-lAVFRsni.js.map +0 -1
- package/dist/use-renown-login-BzOSQETV.js.map +0 -1
- package/dist/useIsEmbedded-BWJ0qb7w.js +0 -26
- package/dist/useIsEmbedded-BWJ0qb7w.js.map +0 -1
- package/dist/useRegistryPackages-BqIWwXV-.js +0 -452
- package/dist/useRegistryPackages-BqIWwXV-.js.map +0 -1
- package/scripts/critical-css.ts +0 -243
- package/src/router/connect-router.ts +0 -170
- package/src/router/drive-route-loader.ts +0 -116
- package/src/router/navigation.ts +0 -230
- package/src/router/perf-marks.test.tsx +0 -98
- package/src/router/perf-marks.ts +0 -97
- package/src/router/route-components.tsx +0 -98
- package/src/router/route-tree.ts +0 -88
- package/src/router/scroll.ts +0 -69
- package/src/router/search.ts +0 -66
- package/src/router/settings.ts +0 -120
- package/src/router/sidebar.ts +0 -55
- package/src/router/titles.test.ts +0 -24
- package/src/router/titles.ts +0 -33
- package/src/routes/core/_app/$.tsx +0 -13
- package/src/routes/core/_app/_content/d/$driveSlug/{-$nodeSlug}.tsx +0 -52
- package/src/routes/core/_app/_content/index.tsx +0 -3
- package/src/routes/core/_app/_content.tsx +0 -9
- package/src/routes/core/_app/settings/about.tsx +0 -20
- package/src/routes/core/_app/settings/ai-assistant.tsx +0 -20
- package/src/routes/core/_app/settings/danger-zone.tsx +0 -21
- package/src/routes/core/_app/settings/default-editors.tsx +0 -20
- package/src/routes/core/_app/settings/package-manager.tsx +0 -20
- package/src/routes/core/_app/settings.tsx +0 -35
- package/src/routes/core/_app.tsx +0 -10
package/src/router/navigation.ts
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
PHDriveTarget,
|
|
3
|
-
PHNavigation,
|
|
4
|
-
PHNavigationTarget,
|
|
5
|
-
PHSettingsTarget,
|
|
6
|
-
SetSearchParams,
|
|
7
|
-
} from "@powerhousedao/reactor-browser";
|
|
8
|
-
import {
|
|
9
|
-
applySearchUpdate,
|
|
10
|
-
findDriveBySlugOrId,
|
|
11
|
-
isSettingsTarget,
|
|
12
|
-
makeDriveSlug,
|
|
13
|
-
OPENED_FROM_STATE_KEY,
|
|
14
|
-
openedFromIndex,
|
|
15
|
-
resolveSearchUpdate,
|
|
16
|
-
} from "@powerhousedao/reactor-browser";
|
|
17
|
-
import type {
|
|
18
|
-
AnyRouter,
|
|
19
|
-
HistoryState,
|
|
20
|
-
MakeRouteMatchUnion,
|
|
21
|
-
} from "@tanstack/react-router";
|
|
22
|
-
import { useRouterState } from "@tanstack/react-router";
|
|
23
|
-
import { useMemo } from "react";
|
|
24
|
-
import type { ConnectRouterBundle } from "./connect-router.js";
|
|
25
|
-
import { markNavigationClick } from "./perf-marks.js";
|
|
26
|
-
import { definedSearch } from "./search.js";
|
|
27
|
-
import { keepOpenedFrom, settingsTabs } from "./settings.js";
|
|
28
|
-
|
|
29
|
-
// Hover intent: a pointer passing over cards doesn't preload each of them.
|
|
30
|
-
const PRELOAD_DELAY_MS = 50;
|
|
31
|
-
|
|
32
|
-
/** The PH navigation backed by `router`; its hooks take the router directly,
|
|
33
|
-
* so they work outside the RouterProvider. */
|
|
34
|
-
export function createConnectNavigation(
|
|
35
|
-
connectRouter: ConnectRouterBundle,
|
|
36
|
-
): PHNavigation & { dispose(): void } {
|
|
37
|
-
const { router, homeRoute, driveRoute, settingsRoute } = connectRouter;
|
|
38
|
-
// Settings tabs can come from a project's routes, unknown to Connect's types.
|
|
39
|
-
const anyRouter = router as unknown as AnyRouter;
|
|
40
|
-
|
|
41
|
-
// A listed drive is addressed by its canonical slug, whatever form came in.
|
|
42
|
-
const driveParams = (target: PHDriveTarget) => {
|
|
43
|
-
const drive = findDriveBySlugOrId(
|
|
44
|
-
router.options.context.store,
|
|
45
|
-
target.driveSlug,
|
|
46
|
-
);
|
|
47
|
-
return {
|
|
48
|
-
driveSlug: drive ? makeDriveSlug(drive) : target.driveSlug,
|
|
49
|
-
nodeSlug: target.nodeSlug || undefined,
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// `true` is the first tab, so the URL names a tab without a redirect.
|
|
54
|
-
const settingsPath = ({ settings }: PHSettingsTarget) => {
|
|
55
|
-
const tab =
|
|
56
|
-
settings === true ? settingsTabs(anyRouter).at(0)?.id : settings;
|
|
57
|
-
return tab ? `${settingsRoute.fullPath}/${tab}` : settingsRoute.fullPath;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// In-document writes keep the entry's state, so its opened-from index too.
|
|
61
|
-
const setSearch: PHNavigation["setSearch"] = (update, options) => {
|
|
62
|
-
void router.navigate({
|
|
63
|
-
to: ".",
|
|
64
|
-
search: (prev) => applySearchUpdate({}, update(definedSearch(prev))),
|
|
65
|
-
state: true,
|
|
66
|
-
replace: options?.replace,
|
|
67
|
-
resetScroll: false,
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const showsSettings = () =>
|
|
72
|
-
router.state.matches.some((match) => match.routeId === settingsRoute.id);
|
|
73
|
-
|
|
74
|
-
// A push remembers the entry it leaves; a replace keeps what that one had,
|
|
75
|
-
// as does a move between settings tabs.
|
|
76
|
-
const openedFromState = (
|
|
77
|
-
replace: boolean | undefined,
|
|
78
|
-
target: PHNavigationTarget | undefined,
|
|
79
|
-
) => {
|
|
80
|
-
const { state } = router.history.location;
|
|
81
|
-
const next =
|
|
82
|
-
replace || (isSettingsTarget(target) && showsSettings())
|
|
83
|
-
? keepOpenedFrom(state)
|
|
84
|
-
: ({
|
|
85
|
-
[OPENED_FROM_STATE_KEY]: state.__TSR_index,
|
|
86
|
-
} as unknown as HistoryState);
|
|
87
|
-
return () => next;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const targetKey = (target: PHNavigationTarget | undefined) => {
|
|
91
|
-
if (!target) return homeRoute.id;
|
|
92
|
-
if (isSettingsTarget(target)) return settingsPath(target);
|
|
93
|
-
const { driveSlug, nodeSlug } = driveParams(target);
|
|
94
|
-
return JSON.stringify([driveSlug, nodeSlug ?? ""]);
|
|
95
|
-
};
|
|
96
|
-
let keyedMatches: readonly MakeRouteMatchUnion[] | undefined;
|
|
97
|
-
let matchesKey: string | undefined;
|
|
98
|
-
const currentKey = (matches: readonly MakeRouteMatchUnion[]) => {
|
|
99
|
-
if (matches === keyedMatches) return matchesKey;
|
|
100
|
-
keyedMatches = matches;
|
|
101
|
-
const drive = matches.find((match) => match.routeId === driveRoute.id);
|
|
102
|
-
const settings = matches.some(
|
|
103
|
-
(match) => match.routeId === settingsRoute.id,
|
|
104
|
-
);
|
|
105
|
-
if (drive) {
|
|
106
|
-
matchesKey = targetKey(drive.params as PHDriveTarget);
|
|
107
|
-
} else if (settings) {
|
|
108
|
-
// A tab's key is its path, as settingsPath builds it.
|
|
109
|
-
matchesKey = matches.at(-1)?.fullPath.replace(/\/$/, "");
|
|
110
|
-
} else {
|
|
111
|
-
matchesKey = matches.find(
|
|
112
|
-
(match) => match.routeId === homeRoute.id,
|
|
113
|
-
)?.routeId;
|
|
114
|
-
}
|
|
115
|
-
return matchesKey;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
// Hrefs depend only on the target and the global params of the current search.
|
|
119
|
-
const hrefs = new Map<string, string>();
|
|
120
|
-
let hrefsSearch: string | undefined;
|
|
121
|
-
|
|
122
|
-
const setSearchParams: SetSearchParams = (update, options) =>
|
|
123
|
-
setSearch((prev) => resolveSearchUpdate(prev, update), options);
|
|
124
|
-
|
|
125
|
-
let preloadTimer: ReturnType<typeof setTimeout> | undefined;
|
|
126
|
-
return {
|
|
127
|
-
location: () => router.history.location,
|
|
128
|
-
// The root route's middlewares add the global params to `search`.
|
|
129
|
-
open: (target, options) => {
|
|
130
|
-
markNavigationClick();
|
|
131
|
-
const search = applySearchUpdate({}, options?.search ?? {});
|
|
132
|
-
const replace = options?.replace;
|
|
133
|
-
const state = openedFromState(replace, target);
|
|
134
|
-
if (!target) {
|
|
135
|
-
void router.navigate({
|
|
136
|
-
to: homeRoute.fullPath,
|
|
137
|
-
search,
|
|
138
|
-
replace,
|
|
139
|
-
state,
|
|
140
|
-
});
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (isSettingsTarget(target)) {
|
|
144
|
-
void anyRouter.navigate({
|
|
145
|
-
to: settingsPath(target),
|
|
146
|
-
search,
|
|
147
|
-
replace,
|
|
148
|
-
state,
|
|
149
|
-
});
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
void router.navigate({
|
|
153
|
-
to: driveRoute.fullPath,
|
|
154
|
-
params: driveParams(target),
|
|
155
|
-
search,
|
|
156
|
-
replace,
|
|
157
|
-
state,
|
|
158
|
-
});
|
|
159
|
-
},
|
|
160
|
-
// The public href, base path included; global params as `open` keeps them.
|
|
161
|
-
hrefFor: (target) => {
|
|
162
|
-
const { searchStr } = router.latestLocation;
|
|
163
|
-
if (searchStr !== hrefsSearch) {
|
|
164
|
-
hrefs.clear();
|
|
165
|
-
hrefsSearch = searchStr;
|
|
166
|
-
}
|
|
167
|
-
const key = targetKey(target);
|
|
168
|
-
let href = hrefs.get(key);
|
|
169
|
-
if (href === undefined) {
|
|
170
|
-
const location = !target
|
|
171
|
-
? router.buildLocation({ to: homeRoute.fullPath, search: {} })
|
|
172
|
-
: isSettingsTarget(target)
|
|
173
|
-
? anyRouter.buildLocation({ to: settingsPath(target), search: {} })
|
|
174
|
-
: router.buildLocation({
|
|
175
|
-
to: driveRoute.fullPath,
|
|
176
|
-
params: driveParams(target),
|
|
177
|
-
search: {},
|
|
178
|
-
});
|
|
179
|
-
href = location.publicHref;
|
|
180
|
-
hrefs.set(key, href);
|
|
181
|
-
}
|
|
182
|
-
return href;
|
|
183
|
-
},
|
|
184
|
-
// One key per shown matches, so each link's selector is a string compare.
|
|
185
|
-
useIsCurrent: (target) => {
|
|
186
|
-
// The settings page itself is current on any of its tabs.
|
|
187
|
-
const anyTab = isSettingsTarget(target) && target.settings === true;
|
|
188
|
-
const key = anyTab ? `${settingsRoute.fullPath}/` : targetKey(target);
|
|
189
|
-
return useRouterState({
|
|
190
|
-
router,
|
|
191
|
-
select: (state) => {
|
|
192
|
-
const current = currentKey(state.matches);
|
|
193
|
-
return anyTab ? !!current?.startsWith(key) : current === key;
|
|
194
|
-
},
|
|
195
|
-
});
|
|
196
|
-
},
|
|
197
|
-
preload: (target) => {
|
|
198
|
-
clearTimeout(preloadTimer);
|
|
199
|
-
if (!target) return;
|
|
200
|
-
preloadTimer = setTimeout(() => {
|
|
201
|
-
const preloading = isSettingsTarget(target)
|
|
202
|
-
? anyRouter.preloadRoute({ to: settingsPath(target) })
|
|
203
|
-
: router.preloadRoute({
|
|
204
|
-
to: driveRoute.fullPath,
|
|
205
|
-
params: driveParams(target),
|
|
206
|
-
});
|
|
207
|
-
preloading.catch(() => undefined);
|
|
208
|
-
}, PRELOAD_DELAY_MS);
|
|
209
|
-
},
|
|
210
|
-
setSearch,
|
|
211
|
-
// The presented matches' params, else the location's.
|
|
212
|
-
useSearchParams() {
|
|
213
|
-
const search = useRouterState({
|
|
214
|
-
router,
|
|
215
|
-
select: (state) =>
|
|
216
|
-
state.matches.at(-1)?.search ?? state.location.search,
|
|
217
|
-
});
|
|
218
|
-
return useMemo(() => definedSearch(search), [search]);
|
|
219
|
-
},
|
|
220
|
-
useSetSearchParams: () => setSearchParams,
|
|
221
|
-
closeOpened: () => {
|
|
222
|
-
const { state } = router.history.location;
|
|
223
|
-
const from = openedFromIndex(state, state.__TSR_index);
|
|
224
|
-
if (from === undefined) return false;
|
|
225
|
-
router.history.go(from - state.__TSR_index);
|
|
226
|
-
return true;
|
|
227
|
-
},
|
|
228
|
-
dispose: () => clearTimeout(preloadTimer),
|
|
229
|
-
};
|
|
230
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// @vitest-environment happy-dom
|
|
2
|
-
|
|
3
|
-
import { act, cleanup, render } from "@testing-library/react";
|
|
4
|
-
import {
|
|
5
|
-
createMemoryHistory,
|
|
6
|
-
createRootRoute,
|
|
7
|
-
createRoute,
|
|
8
|
-
createRouter,
|
|
9
|
-
Outlet,
|
|
10
|
-
RouterProvider,
|
|
11
|
-
} from "@tanstack/react-router";
|
|
12
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
13
|
-
import {
|
|
14
|
-
markNavigationClick,
|
|
15
|
-
markRouterNavigations,
|
|
16
|
-
PERF_STORAGE_KEY,
|
|
17
|
-
ROUTER_MEASURES,
|
|
18
|
-
routerPerfEnabled,
|
|
19
|
-
} from "./perf-marks.js";
|
|
20
|
-
|
|
21
|
-
function mountRouter() {
|
|
22
|
-
const rootRoute = createRootRoute({ component: Outlet });
|
|
23
|
-
const pages = ["a", "b"].map((path) =>
|
|
24
|
-
createRoute({
|
|
25
|
-
getParentRoute: () => rootRoute,
|
|
26
|
-
path,
|
|
27
|
-
loader: () => new Promise((resolve) => setTimeout(resolve, 5)),
|
|
28
|
-
component: () => <p>{path}</p>,
|
|
29
|
-
}),
|
|
30
|
-
);
|
|
31
|
-
const router = createRouter({
|
|
32
|
-
routeTree: rootRoute.addChildren(pages),
|
|
33
|
-
history: createMemoryHistory({ initialEntries: ["/a"] }),
|
|
34
|
-
});
|
|
35
|
-
render(<RouterProvider router={router} />);
|
|
36
|
-
return router;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const measures = () =>
|
|
40
|
-
performance.getEntriesByType("measure").map((entry) => entry.name);
|
|
41
|
-
|
|
42
|
-
async function clickTo(router: ReturnType<typeof mountRouter>, to: string) {
|
|
43
|
-
await vi.waitFor(() => expect(router.state.status).toBe("idle"));
|
|
44
|
-
performance.clearMeasures();
|
|
45
|
-
performance.clearMarks();
|
|
46
|
-
markNavigationClick();
|
|
47
|
-
await act(() => router.navigate({ to }));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
let unmark: (() => void) | undefined;
|
|
51
|
-
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
performance.clearMeasures();
|
|
54
|
-
performance.clearMarks();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
afterEach(() => {
|
|
58
|
-
unmark?.();
|
|
59
|
-
unmark = undefined;
|
|
60
|
-
cleanup();
|
|
61
|
-
localStorage.removeItem(PERF_STORAGE_KEY);
|
|
62
|
-
window.history.replaceState(null, "", "/");
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe("router performance marks", () => {
|
|
66
|
-
it("measures click, loader, commit and total when enabled", async () => {
|
|
67
|
-
const router = mountRouter();
|
|
68
|
-
unmark = markRouterNavigations(router, true);
|
|
69
|
-
await clickTo(router, "/b");
|
|
70
|
-
await vi.waitFor(() =>
|
|
71
|
-
expect(measures()).toEqual(
|
|
72
|
-
expect.arrayContaining(Object.values(ROUTER_MEASURES)),
|
|
73
|
-
),
|
|
74
|
-
);
|
|
75
|
-
const [loader] = performance.getEntriesByName(ROUTER_MEASURES.loader);
|
|
76
|
-
expect(loader.duration).toBeGreaterThan(0);
|
|
77
|
-
expect(performance.getEntriesByName("nav:click", "mark")).toHaveLength(1);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("writes nothing when disabled", async () => {
|
|
81
|
-
const router = mountRouter();
|
|
82
|
-
unmark = markRouterNavigations(router, false);
|
|
83
|
-
await clickTo(router, "/b");
|
|
84
|
-
await act(() => new Promise((resolve) => setTimeout(resolve, 50)));
|
|
85
|
-
expect(measures()).toEqual([]);
|
|
86
|
-
expect(performance.getEntriesByType("mark")).toEqual([]);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("is on in dev, and elsewhere only with ?perf=1 or the storage flag", () => {
|
|
90
|
-
expect(routerPerfEnabled(true)).toBe(true);
|
|
91
|
-
expect(routerPerfEnabled(false)).toBe(false);
|
|
92
|
-
window.history.replaceState(null, "", "/?perf=1");
|
|
93
|
-
expect(routerPerfEnabled(false)).toBe(true);
|
|
94
|
-
window.history.replaceState(null, "", "/");
|
|
95
|
-
localStorage.setItem(PERF_STORAGE_KEY, "1");
|
|
96
|
-
expect(routerPerfEnabled(false)).toBe(true);
|
|
97
|
-
});
|
|
98
|
-
});
|
package/src/router/perf-marks.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
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
|
-
}
|
package/src/router/route-tree.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
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
|
-
>;
|
package/src/router/scroll.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
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
|
-
}
|