one 1.2.57 → 1.2.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/build.cjs +3 -1
- package/dist/cjs/cli/build.js +1 -1
- package/dist/cjs/cli/build.js.map +1 -1
- package/dist/cjs/cli/build.native.js +13 -12
- package/dist/cjs/cli/build.native.js.map +1 -1
- package/dist/cjs/cli/buildPage.cjs +1 -1
- package/dist/cjs/cli/buildPage.js +1 -1
- package/dist/cjs/cli/buildPage.native.js +2 -2
- package/dist/cjs/cli/buildPage.native.js.map +1 -1
- package/dist/cjs/cli/dev.cjs +4 -4
- package/dist/cjs/cli/dev.js +4 -4
- package/dist/cjs/cli/dev.js.map +1 -1
- package/dist/cjs/cli/dev.native.js +4 -4
- package/dist/cjs/cli/dev.native.js.map +1 -1
- package/dist/cjs/cli/generateRoutes.cjs +1 -1
- package/dist/cjs/cli/generateRoutes.js +1 -1
- package/dist/cjs/cli/generateRoutes.native.js +1 -1
- package/dist/cjs/cli/generateRoutes.native.js.map +1 -1
- package/dist/cjs/cli/generateSitemap.native.js +7 -7
- package/dist/cjs/cli/generateSitemap.native.js.map +1 -1
- package/dist/cjs/config.native.js +2 -2
- package/dist/cjs/config.native.js.map +1 -1
- package/dist/cjs/constants.native.js +1 -1
- package/dist/cjs/constants.native.js.map +1 -1
- package/dist/cjs/createApp.cjs +2 -1
- package/dist/cjs/createApp.js +2 -2
- package/dist/cjs/createApp.js.map +1 -1
- package/dist/cjs/createHandleRequest.test.js +3 -1
- package/dist/cjs/createHandleRequest.test.js.map +1 -1
- package/dist/cjs/createHandleRequest.test.native.js.map +1 -1
- package/dist/cjs/devtools/registry.cjs +30 -0
- package/dist/cjs/devtools/registry.js +25 -0
- package/dist/cjs/devtools/registry.js.map +6 -0
- package/dist/cjs/devtools/registry.native.js +33 -0
- package/dist/cjs/devtools/registry.native.js.map +1 -0
- package/dist/cjs/fork/NavigationContainer.native.js +5 -5
- package/dist/cjs/fork/NavigationContainer.native.js.map +1 -1
- package/dist/cjs/fork/createMemoryHistory.cjs +20 -9
- package/dist/cjs/fork/createMemoryHistory.js +22 -4
- package/dist/cjs/fork/createMemoryHistory.js.map +1 -1
- package/dist/cjs/fork/createMemoryHistory.native.js +22 -11
- package/dist/cjs/fork/createMemoryHistory.native.js.map +1 -1
- package/dist/cjs/fork/extractPathFromURL.native.js +8 -8
- package/dist/cjs/fork/extractPathFromURL.native.js.map +1 -1
- package/dist/cjs/fork/findFocusedRoute.native.js +2 -3
- package/dist/cjs/fork/findFocusedRoute.native.js.map +1 -1
- package/dist/cjs/fork/getPathFromState-mods.native.js +2 -3
- package/dist/cjs/fork/getPathFromState-mods.native.js.map +1 -1
- package/dist/cjs/fork/getStateFromPath-mods.native.js +3 -3
- package/dist/cjs/fork/getStateFromPath-mods.native.js.map +1 -1
- package/dist/cjs/fork/useLinking.cjs +11 -5
- package/dist/cjs/fork/useLinking.js +6 -6
- package/dist/cjs/fork/useLinking.js.map +1 -1
- package/dist/cjs/fork/useLinking.native.js.map +1 -1
- package/dist/cjs/head/url.native.js +2 -3
- package/dist/cjs/head/url.native.js.map +1 -1
- package/dist/cjs/hooks.js.map +1 -1
- package/dist/cjs/hooks.native.js.map +1 -1
- package/dist/cjs/index.cjs +17 -1
- package/dist/cjs/index.js +12 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +17 -1
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/layouts/withLayoutContext.cjs +34 -15
- package/dist/cjs/layouts/withLayoutContext.js +29 -13
- package/dist/cjs/layouts/withLayoutContext.js.map +1 -1
- package/dist/cjs/layouts/withLayoutContext.native.js +42 -19
- package/dist/cjs/layouts/withLayoutContext.native.js.map +1 -1
- package/dist/cjs/link/Link.cjs +5 -2
- package/dist/cjs/link/Link.js +3 -2
- package/dist/cjs/link/Link.js.map +1 -1
- package/dist/cjs/link/Link.native.js +6 -1
- package/dist/cjs/link/Link.native.js.map +1 -1
- package/dist/cjs/link/href.native.js +2 -2
- package/dist/cjs/link/href.native.js.map +1 -1
- package/dist/cjs/link/useLinkTo.cjs +11 -3
- package/dist/cjs/link/useLinkTo.js +6 -3
- package/dist/cjs/link/useLinkTo.js.map +1 -1
- package/dist/cjs/link/useLinkTo.native.js +11 -3
- package/dist/cjs/link/useLinkTo.native.js.map +1 -1
- package/dist/cjs/router/Route.js.map +1 -1
- package/dist/cjs/router/Route.native.js.map +1 -1
- package/dist/cjs/router/findRouteNode.cjs +70 -0
- package/dist/cjs/router/findRouteNode.js +72 -0
- package/dist/cjs/router/findRouteNode.js.map +6 -0
- package/dist/cjs/router/findRouteNode.native.js +104 -0
- package/dist/cjs/router/findRouteNode.native.js.map +1 -0
- package/dist/cjs/router/getRoutes.native.js +3 -3
- package/dist/cjs/router/getRoutes.native.js.map +1 -1
- package/dist/cjs/router/router.cjs +160 -11
- package/dist/cjs/router/router.js +142 -7
- package/dist/cjs/router/router.js.map +2 -2
- package/dist/cjs/router/router.native.js +247 -67
- package/dist/cjs/router/router.native.js.map +1 -1
- package/dist/cjs/router/useNavigation.js.map +1 -1
- package/dist/cjs/router/useNavigation.native.js.map +1 -1
- package/dist/cjs/router/useScreens.cjs +1 -1
- package/dist/cjs/router/useScreens.js +1 -1
- package/dist/cjs/router/useScreens.js.map +1 -1
- package/dist/cjs/router/useScreens.native.js +6 -3
- package/dist/cjs/router/useScreens.native.js.map +1 -1
- package/dist/cjs/router/utils/getNavigateAction.native.js +2 -4
- package/dist/cjs/router/utils/getNavigateAction.native.js.map +1 -1
- package/dist/cjs/server/oneServe.js.map +1 -1
- package/dist/cjs/server/oneServe.native.js +4 -4
- package/dist/cjs/server/oneServe.native.js.map +1 -1
- package/dist/cjs/server/setupBuildOptions.native.js +1 -1
- package/dist/cjs/server/setupBuildOptions.native.js.map +1 -1
- package/dist/cjs/ui/common.native.js +6 -5
- package/dist/cjs/ui/common.native.js.map +1 -1
- package/dist/cjs/useBlocker.cjs +158 -0
- package/dist/cjs/useBlocker.js +145 -0
- package/dist/cjs/useBlocker.js.map +6 -0
- package/dist/cjs/useBlocker.native.js +89 -0
- package/dist/cjs/useBlocker.native.js.map +1 -0
- package/dist/cjs/useFocusEffect.cjs +2 -2
- package/dist/cjs/useFocusEffect.js +2 -2
- package/dist/cjs/useFocusEffect.js.map +1 -1
- package/dist/cjs/useFocusEffect.native.js +2 -2
- package/dist/cjs/useFocusEffect.native.js.map +1 -1
- package/dist/cjs/useLoader.cjs +69 -3
- package/dist/cjs/useLoader.js +57 -4
- package/dist/cjs/useLoader.js.map +2 -2
- package/dist/cjs/useLoader.native.js +90 -6
- package/dist/cjs/useLoader.native.js.map +1 -1
- package/dist/cjs/useScrollGroup.cjs +37 -0
- package/dist/cjs/useScrollGroup.js +30 -0
- package/dist/cjs/useScrollGroup.js.map +6 -0
- package/dist/cjs/useScrollGroup.native.js +29 -0
- package/dist/cjs/useScrollGroup.native.js.map +1 -0
- package/dist/cjs/validateParams.cjs +80 -0
- package/dist/cjs/validateParams.js +84 -0
- package/dist/cjs/validateParams.js.map +6 -0
- package/dist/cjs/validateParams.native.js +180 -0
- package/dist/cjs/validateParams.native.js.map +1 -0
- package/dist/cjs/validateSearch.cjs +104 -0
- package/dist/cjs/validateSearch.js +99 -0
- package/dist/cjs/validateSearch.js.map +6 -0
- package/dist/cjs/validateSearch.native.js +202 -0
- package/dist/cjs/validateSearch.native.js.map +1 -0
- package/dist/cjs/vercel/build/buildVercelOutputDirectory.native.js +2 -2
- package/dist/cjs/vercel/build/buildVercelOutputDirectory.native.js.map +1 -1
- package/dist/cjs/views/ErrorBoundary.cjs +293 -10
- package/dist/cjs/views/ErrorBoundary.js +328 -8
- package/dist/cjs/views/ErrorBoundary.js.map +2 -2
- package/dist/cjs/views/ErrorBoundary.native.js +159 -4
- package/dist/cjs/views/ErrorBoundary.native.js.map +1 -1
- package/dist/cjs/views/Navigator.cjs +10 -3
- package/dist/cjs/views/Navigator.js +11 -3
- package/dist/cjs/views/Navigator.js.map +1 -1
- package/dist/cjs/views/Navigator.native.js +15 -6
- package/dist/cjs/views/Navigator.native.js.map +1 -1
- package/dist/cjs/views/Protected.cjs +36 -0
- package/dist/cjs/views/Protected.js +27 -0
- package/dist/cjs/views/Protected.js.map +6 -0
- package/dist/cjs/views/Protected.native.js +44 -0
- package/dist/cjs/views/Protected.native.js.map +1 -0
- package/dist/cjs/views/RootErrorBoundary.cjs +193 -8
- package/dist/cjs/views/RootErrorBoundary.js +213 -8
- package/dist/cjs/views/RootErrorBoundary.js.map +1 -1
- package/dist/cjs/views/RootErrorBoundary.native.js +192 -8
- package/dist/cjs/views/RootErrorBoundary.native.js.map +1 -1
- package/dist/cjs/views/ScrollBehavior.cjs +49 -11
- package/dist/cjs/views/ScrollBehavior.js +47 -11
- package/dist/cjs/views/ScrollBehavior.js.map +1 -1
- package/dist/cjs/views/ScrollBehavior.native.js +68 -10
- package/dist/cjs/views/ScrollBehavior.native.js.map +1 -1
- package/dist/cjs/views/SourceInspector.cjs +28 -0
- package/dist/cjs/views/SourceInspector.js +23 -0
- package/dist/cjs/views/SourceInspector.js.map +6 -0
- package/dist/cjs/views/SourceInspector.native.js +32 -0
- package/dist/cjs/views/SourceInspector.native.js.map +1 -0
- package/dist/cjs/views/Try.cjs +40 -7
- package/dist/cjs/views/Try.js +38 -4
- package/dist/cjs/views/Try.js.map +1 -1
- package/dist/cjs/views/Try.native.js +42 -7
- package/dist/cjs/views/Try.native.js.map +1 -1
- package/dist/cjs/vite/DevHead.cjs +797 -43
- package/dist/cjs/vite/DevHead.js +802 -51
- package/dist/cjs/vite/DevHead.js.map +1 -1
- package/dist/cjs/vite/DevHead.native.js +783 -1
- package/dist/cjs/vite/DevHead.native.js.map +1 -1
- package/dist/cjs/vite/one.cjs +7 -1
- package/dist/cjs/vite/one.js +7 -2
- package/dist/cjs/vite/one.js.map +1 -1
- package/dist/cjs/vite/one.native.js +17 -7
- package/dist/cjs/vite/one.native.js.map +1 -1
- package/dist/cjs/vite/plugins/SSRCSSPlugin.cjs +44 -4
- package/dist/cjs/vite/plugins/SSRCSSPlugin.js +48 -4
- package/dist/cjs/vite/plugins/SSRCSSPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/SSRCSSPlugin.native.js +62 -5
- package/dist/cjs/vite/plugins/SSRCSSPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.cjs +34 -15
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.js +24 -3
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.native.js +55 -19
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.test.cjs +129 -0
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.test.js +129 -0
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.test.js.map +6 -0
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.test.native.js +140 -0
- package/dist/cjs/vite/plugins/clientTreeShakePlugin.test.native.js.map +1 -0
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js +6 -3
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +3 -3
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.cjs +5 -1
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.js +11 -6
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.native.js +1 -0
- package/dist/cjs/vite/plugins/generateFileSystemRouteTypesPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/sourceInspectorPlugin.cjs +155 -0
- package/dist/cjs/vite/plugins/sourceInspectorPlugin.js +148 -0
- package/dist/cjs/vite/plugins/sourceInspectorPlugin.js.map +6 -0
- package/dist/cjs/vite/plugins/sourceInspectorPlugin.native.js +231 -0
- package/dist/cjs/vite/plugins/sourceInspectorPlugin.native.js.map +1 -0
- package/dist/cjs/vite/plugins/virtualEntryPlugin.cjs +25 -6
- package/dist/cjs/vite/plugins/virtualEntryPlugin.js +16 -6
- package/dist/cjs/vite/plugins/virtualEntryPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js +26 -7
- package/dist/cjs/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
- package/dist/esm/cli/build.js +1 -1
- package/dist/esm/cli/build.js.map +1 -1
- package/dist/esm/cli/build.mjs +3 -1
- package/dist/esm/cli/build.mjs.map +1 -1
- package/dist/esm/cli/build.native.js +13 -12
- package/dist/esm/cli/build.native.js.map +1 -1
- package/dist/esm/cli/buildPage.js +1 -1
- package/dist/esm/cli/buildPage.mjs +1 -1
- package/dist/esm/cli/buildPage.mjs.map +1 -1
- package/dist/esm/cli/buildPage.native.js +2 -2
- package/dist/esm/cli/buildPage.native.js.map +1 -1
- package/dist/esm/cli/dev.js +4 -4
- package/dist/esm/cli/dev.js.map +1 -1
- package/dist/esm/cli/dev.mjs +4 -4
- package/dist/esm/cli/dev.mjs.map +1 -1
- package/dist/esm/cli/dev.native.js +4 -4
- package/dist/esm/cli/dev.native.js.map +1 -1
- package/dist/esm/cli/generateRoutes.js +1 -1
- package/dist/esm/cli/generateRoutes.mjs +1 -1
- package/dist/esm/cli/generateRoutes.mjs.map +1 -1
- package/dist/esm/cli/generateRoutes.native.js +1 -1
- package/dist/esm/cli/generateRoutes.native.js.map +1 -1
- package/dist/esm/cli/generateSitemap.native.js +7 -7
- package/dist/esm/cli/generateSitemap.native.js.map +1 -1
- package/dist/esm/config.native.js +2 -2
- package/dist/esm/config.native.js.map +1 -1
- package/dist/esm/constants.native.js +2 -2
- package/dist/esm/constants.native.js.map +1 -1
- package/dist/esm/createApp.js +2 -2
- package/dist/esm/createApp.js.map +1 -1
- package/dist/esm/createApp.mjs +2 -1
- package/dist/esm/createApp.mjs.map +1 -1
- package/dist/esm/createHandleRequest.test.js +3 -1
- package/dist/esm/createHandleRequest.test.js.map +1 -1
- package/dist/esm/createHandleRequest.test.mjs.map +1 -1
- package/dist/esm/createHandleRequest.test.native.js.map +1 -1
- package/dist/esm/devtools/registry.js +9 -0
- package/dist/esm/devtools/registry.js.map +6 -0
- package/dist/esm/devtools/registry.mjs +6 -0
- package/dist/esm/devtools/registry.mjs.map +1 -0
- package/dist/esm/devtools/registry.native.js +6 -0
- package/dist/esm/devtools/registry.native.js.map +1 -0
- package/dist/esm/fork/NavigationContainer.native.js +5 -5
- package/dist/esm/fork/NavigationContainer.native.js.map +1 -1
- package/dist/esm/fork/createMemoryHistory.js +22 -4
- package/dist/esm/fork/createMemoryHistory.js.map +1 -1
- package/dist/esm/fork/createMemoryHistory.mjs +20 -9
- package/dist/esm/fork/createMemoryHistory.mjs.map +1 -1
- package/dist/esm/fork/createMemoryHistory.native.js +22 -11
- package/dist/esm/fork/createMemoryHistory.native.js.map +1 -1
- package/dist/esm/fork/extractPathFromURL.native.js +8 -8
- package/dist/esm/fork/extractPathFromURL.native.js.map +1 -1
- package/dist/esm/fork/findFocusedRoute.native.js +2 -3
- package/dist/esm/fork/findFocusedRoute.native.js.map +1 -1
- package/dist/esm/fork/getPathFromState-mods.native.js +2 -3
- package/dist/esm/fork/getPathFromState-mods.native.js.map +1 -1
- package/dist/esm/fork/getStateFromPath-mods.native.js +3 -3
- package/dist/esm/fork/getStateFromPath-mods.native.js.map +1 -1
- package/dist/esm/fork/useLinking.js +6 -5
- package/dist/esm/fork/useLinking.js.map +1 -1
- package/dist/esm/fork/useLinking.mjs +11 -5
- package/dist/esm/fork/useLinking.mjs.map +1 -1
- package/dist/esm/fork/useLinking.native.js.map +1 -1
- package/dist/esm/head/url.native.js +2 -3
- package/dist/esm/head/url.native.js.map +1 -1
- package/dist/esm/hooks.js.map +1 -1
- package/dist/esm/hooks.mjs.map +1 -1
- package/dist/esm/hooks.native.js.map +1 -1
- package/dist/esm/index.js +30 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +8 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +8 -2
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/layouts/withLayoutContext.js +30 -12
- package/dist/esm/layouts/withLayoutContext.js.map +1 -1
- package/dist/esm/layouts/withLayoutContext.mjs +34 -15
- package/dist/esm/layouts/withLayoutContext.mjs.map +1 -1
- package/dist/esm/layouts/withLayoutContext.native.js +42 -19
- package/dist/esm/layouts/withLayoutContext.native.js.map +1 -1
- package/dist/esm/link/Link.js +3 -2
- package/dist/esm/link/Link.js.map +1 -1
- package/dist/esm/link/Link.mjs +5 -2
- package/dist/esm/link/Link.mjs.map +1 -1
- package/dist/esm/link/Link.native.js +6 -1
- package/dist/esm/link/Link.native.js.map +1 -1
- package/dist/esm/link/href.native.js +2 -2
- package/dist/esm/link/href.native.js.map +1 -1
- package/dist/esm/link/useLinkTo.js +6 -3
- package/dist/esm/link/useLinkTo.js.map +1 -1
- package/dist/esm/link/useLinkTo.mjs +11 -3
- package/dist/esm/link/useLinkTo.mjs.map +1 -1
- package/dist/esm/link/useLinkTo.native.js +11 -3
- package/dist/esm/link/useLinkTo.native.js.map +1 -1
- package/dist/esm/router/Route.js.map +1 -1
- package/dist/esm/router/Route.mjs.map +1 -1
- package/dist/esm/router/Route.native.js.map +1 -1
- package/dist/esm/router/findRouteNode.js +56 -0
- package/dist/esm/router/findRouteNode.js.map +6 -0
- package/dist/esm/router/findRouteNode.mjs +44 -0
- package/dist/esm/router/findRouteNode.mjs.map +1 -0
- package/dist/esm/router/findRouteNode.native.js +75 -0
- package/dist/esm/router/findRouteNode.native.js.map +1 -0
- package/dist/esm/router/getRoutes.native.js +3 -3
- package/dist/esm/router/getRoutes.native.js.map +1 -1
- package/dist/esm/router/router.js +154 -6
- package/dist/esm/router/router.js.map +1 -1
- package/dist/esm/router/router.mjs +151 -10
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +238 -66
- package/dist/esm/router/router.native.js.map +1 -1
- package/dist/esm/router/useNavigation.js.map +1 -1
- package/dist/esm/router/useNavigation.mjs.map +1 -1
- package/dist/esm/router/useNavigation.native.js.map +1 -1
- package/dist/esm/router/useScreens.js +1 -1
- package/dist/esm/router/useScreens.js.map +1 -1
- package/dist/esm/router/useScreens.mjs +1 -1
- package/dist/esm/router/useScreens.mjs.map +1 -1
- package/dist/esm/router/useScreens.native.js +6 -3
- package/dist/esm/router/useScreens.native.js.map +1 -1
- package/dist/esm/router/utils/getNavigateAction.native.js +2 -4
- package/dist/esm/router/utils/getNavigateAction.native.js.map +1 -1
- package/dist/esm/server/oneServe.js.map +1 -1
- package/dist/esm/server/oneServe.mjs.map +1 -1
- package/dist/esm/server/oneServe.native.js +4 -4
- package/dist/esm/server/oneServe.native.js.map +1 -1
- package/dist/esm/server/setupBuildOptions.native.js +1 -1
- package/dist/esm/server/setupBuildOptions.native.js.map +1 -1
- package/dist/esm/ui/common.native.js +6 -5
- package/dist/esm/ui/common.native.js.map +1 -1
- package/dist/esm/useBlocker.js +122 -0
- package/dist/esm/useBlocker.js.map +6 -0
- package/dist/esm/useBlocker.mjs +123 -0
- package/dist/esm/useBlocker.mjs.map +1 -0
- package/dist/esm/useBlocker.native.js +51 -0
- package/dist/esm/useBlocker.native.js.map +1 -0
- package/dist/esm/useFocusEffect.js +2 -2
- package/dist/esm/useFocusEffect.js.map +1 -1
- package/dist/esm/useFocusEffect.mjs +2 -2
- package/dist/esm/useFocusEffect.mjs.map +1 -1
- package/dist/esm/useFocusEffect.native.js +2 -2
- package/dist/esm/useFocusEffect.native.js.map +1 -1
- package/dist/esm/useLoader.js +57 -3
- package/dist/esm/useLoader.js.map +2 -2
- package/dist/esm/useLoader.mjs +69 -4
- package/dist/esm/useLoader.mjs.map +1 -1
- package/dist/esm/useLoader.native.js +90 -7
- package/dist/esm/useLoader.native.js.map +1 -1
- package/dist/esm/useScrollGroup.js +16 -0
- package/dist/esm/useScrollGroup.js.map +6 -0
- package/dist/esm/useScrollGroup.mjs +14 -0
- package/dist/esm/useScrollGroup.mjs.map +1 -0
- package/dist/esm/useScrollGroup.native.js +3 -0
- package/dist/esm/useScrollGroup.native.js.map +1 -0
- package/dist/esm/validateParams.js +68 -0
- package/dist/esm/validateParams.js.map +6 -0
- package/dist/esm/validateParams.mjs +54 -0
- package/dist/esm/validateParams.mjs.map +1 -0
- package/dist/esm/validateParams.native.js +151 -0
- package/dist/esm/validateParams.native.js.map +1 -0
- package/dist/esm/validateSearch.js +83 -0
- package/dist/esm/validateSearch.js.map +6 -0
- package/dist/esm/validateSearch.mjs +77 -0
- package/dist/esm/validateSearch.mjs.map +1 -0
- package/dist/esm/validateSearch.native.js +172 -0
- package/dist/esm/validateSearch.native.js.map +1 -0
- package/dist/esm/vercel/build/buildVercelOutputDirectory.native.js +2 -2
- package/dist/esm/vercel/build/buildVercelOutputDirectory.native.js.map +1 -1
- package/dist/esm/views/ErrorBoundary.js +325 -7
- package/dist/esm/views/ErrorBoundary.js.map +2 -2
- package/dist/esm/views/ErrorBoundary.mjs +289 -6
- package/dist/esm/views/ErrorBoundary.mjs.map +1 -1
- package/dist/esm/views/ErrorBoundary.native.js +159 -4
- package/dist/esm/views/ErrorBoundary.native.js.map +1 -1
- package/dist/esm/views/Navigator.js +11 -2
- package/dist/esm/views/Navigator.js.map +1 -1
- package/dist/esm/views/Navigator.mjs +10 -3
- package/dist/esm/views/Navigator.mjs.map +1 -1
- package/dist/esm/views/Navigator.native.js +15 -6
- package/dist/esm/views/Navigator.native.js.map +1 -1
- package/dist/esm/views/Protected.js +14 -0
- package/dist/esm/views/Protected.js.map +6 -0
- package/dist/esm/views/Protected.mjs +11 -0
- package/dist/esm/views/Protected.mjs.map +1 -0
- package/dist/esm/views/Protected.native.js +16 -0
- package/dist/esm/views/Protected.native.js.map +1 -0
- package/dist/esm/views/RootErrorBoundary.js +214 -7
- package/dist/esm/views/RootErrorBoundary.js.map +1 -1
- package/dist/esm/views/RootErrorBoundary.mjs +192 -7
- package/dist/esm/views/RootErrorBoundary.mjs.map +1 -1
- package/dist/esm/views/RootErrorBoundary.native.js +191 -7
- package/dist/esm/views/RootErrorBoundary.native.js.map +1 -1
- package/dist/esm/views/ScrollBehavior.js +47 -11
- package/dist/esm/views/ScrollBehavior.js.map +1 -1
- package/dist/esm/views/ScrollBehavior.mjs +48 -11
- package/dist/esm/views/ScrollBehavior.mjs.map +1 -1
- package/dist/esm/views/ScrollBehavior.native.js +67 -10
- package/dist/esm/views/ScrollBehavior.native.js.map +1 -1
- package/dist/esm/views/SourceInspector.js +7 -0
- package/dist/esm/views/SourceInspector.js.map +6 -0
- package/dist/esm/views/SourceInspector.mjs +5 -0
- package/dist/esm/views/SourceInspector.mjs.map +1 -0
- package/dist/esm/views/SourceInspector.native.js +6 -0
- package/dist/esm/views/SourceInspector.native.js.map +1 -0
- package/dist/esm/views/Try.js +38 -4
- package/dist/esm/views/Try.js.map +1 -1
- package/dist/esm/views/Try.mjs +40 -7
- package/dist/esm/views/Try.mjs.map +1 -1
- package/dist/esm/views/Try.native.js +42 -7
- package/dist/esm/views/Try.native.js.map +1 -1
- package/dist/esm/vite/DevHead.js +802 -51
- package/dist/esm/vite/DevHead.js.map +1 -1
- package/dist/esm/vite/DevHead.mjs +797 -43
- package/dist/esm/vite/DevHead.mjs.map +1 -1
- package/dist/esm/vite/DevHead.native.js +782 -0
- package/dist/esm/vite/DevHead.native.js.map +1 -1
- package/dist/esm/vite/one.js +7 -1
- package/dist/esm/vite/one.js.map +1 -1
- package/dist/esm/vite/one.mjs +7 -1
- package/dist/esm/vite/one.mjs.map +1 -1
- package/dist/esm/vite/one.native.js +17 -7
- package/dist/esm/vite/one.native.js.map +1 -1
- package/dist/esm/vite/plugins/SSRCSSPlugin.js +48 -4
- package/dist/esm/vite/plugins/SSRCSSPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/SSRCSSPlugin.mjs +44 -4
- package/dist/esm/vite/plugins/SSRCSSPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/SSRCSSPlugin.native.js +61 -4
- package/dist/esm/vite/plugins/SSRCSSPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/clientTreeShakePlugin.js +24 -3
- package/dist/esm/vite/plugins/clientTreeShakePlugin.js.map +1 -1
- package/dist/esm/vite/plugins/clientTreeShakePlugin.mjs +34 -15
- package/dist/esm/vite/plugins/clientTreeShakePlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/clientTreeShakePlugin.native.js +55 -19
- package/dist/esm/vite/plugins/clientTreeShakePlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/clientTreeShakePlugin.test.js +130 -0
- package/dist/esm/vite/plugins/clientTreeShakePlugin.test.js.map +6 -0
- package/dist/esm/vite/plugins/clientTreeShakePlugin.test.mjs +130 -0
- package/dist/esm/vite/plugins/clientTreeShakePlugin.test.mjs.map +1 -0
- package/dist/esm/vite/plugins/clientTreeShakePlugin.test.native.js +138 -0
- package/dist/esm/vite/plugins/clientTreeShakePlugin.test.native.js.map +1 -0
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js +6 -3
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +3 -3
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.js +11 -6
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.mjs +5 -1
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.native.js +1 -0
- package/dist/esm/vite/plugins/generateFileSystemRouteTypesPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/sourceInspectorPlugin.js +126 -0
- package/dist/esm/vite/plugins/sourceInspectorPlugin.js.map +6 -0
- package/dist/esm/vite/plugins/sourceInspectorPlugin.mjs +121 -0
- package/dist/esm/vite/plugins/sourceInspectorPlugin.mjs.map +1 -0
- package/dist/esm/vite/plugins/sourceInspectorPlugin.native.js +194 -0
- package/dist/esm/vite/plugins/sourceInspectorPlugin.native.js.map +1 -0
- package/dist/esm/vite/plugins/virtualEntryPlugin.js +16 -6
- package/dist/esm/vite/plugins/virtualEntryPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.mjs +25 -6
- package/dist/esm/vite/plugins/virtualEntryPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/virtualEntryPlugin.native.js +26 -7
- package/dist/esm/vite/plugins/virtualEntryPlugin.native.js.map +1 -1
- package/package.json +16 -14
- package/src/cli/build.ts +1 -1
- package/src/cli/buildPage.ts +1 -1
- package/src/cli/dev.ts +4 -4
- package/src/cli/generateRoutes.ts +1 -1
- package/src/createApp.tsx +11 -1
- package/src/createHandleRequest.test.ts +3 -1
- package/src/devtools/registry.ts +21 -0
- package/src/fork/createMemoryHistory.tsx +43 -11
- package/src/fork/useLinking.ts +14 -4
- package/src/hooks.tsx +71 -21
- package/src/index.ts +34 -1
- package/src/interfaces/router.ts +48 -0
- package/src/layouts/withLayoutContext.tsx +48 -8
- package/src/link/Link.tsx +7 -2
- package/src/link/useLinkTo.tsx +7 -3
- package/src/router/Route.tsx +32 -3
- package/src/router/findRouteNode.ts +127 -0
- package/src/router/router.ts +291 -2
- package/src/router/useNavigation.ts +12 -3
- package/src/router/useScreens.tsx +9 -3
- package/src/useBlocker.native.ts +153 -0
- package/src/useBlocker.ts +340 -0
- package/src/useFocusEffect.ts +18 -5
- package/src/useLoader.ts +193 -2
- package/src/useScrollGroup.native.ts +7 -0
- package/src/useScrollGroup.ts +35 -0
- package/src/validateParams.ts +196 -0
- package/src/validateSearch.ts +241 -0
- package/src/views/ErrorBoundary.tsx +154 -156
- package/src/views/ErrorBoundary.web.tsx +321 -0
- package/src/views/Navigator.tsx +18 -2
- package/src/views/Protected.tsx +62 -0
- package/src/views/RootErrorBoundary.tsx +214 -17
- package/src/views/ScrollBehavior.tsx +82 -3
- package/src/views/SourceInspector.tsx +39 -0
- package/src/views/Try.tsx +81 -12
- package/src/vite/DevHead.tsx +819 -54
- package/src/vite/one.ts +13 -0
- package/src/vite/plugins/SSRCSSPlugin.ts +104 -0
- package/src/vite/plugins/clientTreeShakePlugin.test.ts +174 -0
- package/src/vite/plugins/clientTreeShakePlugin.ts +50 -4
- package/src/vite/plugins/fileSystemRouterPlugin.tsx +11 -8
- package/src/vite/plugins/generateFileSystemRouteTypesPlugin.tsx +4 -0
- package/src/vite/plugins/sourceInspectorPlugin.ts +246 -0
- package/src/vite/plugins/virtualEntryPlugin.ts +36 -10
- package/src/vite/types.ts +28 -0
- package/types/createApp.d.ts +5 -0
- package/types/createApp.d.ts.map +1 -1
- package/types/devtools/registry.d.ts +15 -0
- package/types/devtools/registry.d.ts.map +1 -0
- package/types/fork/createMemoryHistory.d.ts +8 -3
- package/types/fork/createMemoryHistory.d.ts.map +1 -1
- package/types/fork/useLinking.d.ts.map +1 -1
- package/types/hooks.d.ts +71 -20
- package/types/hooks.d.ts.map +1 -1
- package/types/index.d.ts +8 -1
- package/types/index.d.ts.map +1 -1
- package/types/interfaces/router.d.ts +47 -0
- package/types/interfaces/router.d.ts.map +1 -1
- package/types/layouts/Drawer.d.ts +15 -11
- package/types/layouts/Drawer.d.ts.map +1 -1
- package/types/layouts/withLayoutContext.d.ts +2 -1
- package/types/layouts/withLayoutContext.d.ts.map +1 -1
- package/types/link/Link.d.ts.map +1 -1
- package/types/link/useLinkTo.d.ts +1 -0
- package/types/link/useLinkTo.d.ts.map +1 -1
- package/types/router/Route.d.ts +32 -3
- package/types/router/Route.d.ts.map +1 -1
- package/types/router/findRouteNode.d.ts +31 -0
- package/types/router/findRouteNode.d.ts.map +1 -0
- package/types/router/router.d.ts +35 -0
- package/types/router/router.d.ts.map +1 -1
- package/types/router/useNavigation.d.ts +12 -3
- package/types/router/useNavigation.d.ts.map +1 -1
- package/types/router/useScreens.d.ts +2 -0
- package/types/router/useScreens.d.ts.map +1 -1
- package/types/server/oneServe.d.ts.map +1 -1
- package/types/ui/TabContext.d.ts +1 -1
- package/types/ui/TabContext.d.ts.map +1 -1
- package/types/ui/Tabs.d.ts +2 -2
- package/types/ui/Tabs.d.ts.map +1 -1
- package/types/useBlocker.d.ts +72 -0
- package/types/useBlocker.d.ts.map +1 -0
- package/types/useBlocker.native.d.ts +60 -0
- package/types/useBlocker.native.d.ts.map +1 -0
- package/types/useFocusEffect.d.ts +17 -4
- package/types/useFocusEffect.d.ts.map +1 -1
- package/types/useLoader.d.ts +63 -0
- package/types/useLoader.d.ts.map +1 -1
- package/types/useScrollGroup.d.ts +18 -0
- package/types/useScrollGroup.d.ts.map +1 -0
- package/types/useScrollGroup.native.d.ts +6 -0
- package/types/useScrollGroup.native.d.ts.map +1 -0
- package/types/validateParams.d.ts +85 -0
- package/types/validateParams.d.ts.map +1 -0
- package/types/validateSearch.d.ts +107 -0
- package/types/validateSearch.d.ts.map +1 -0
- package/types/views/ErrorBoundary.d.ts +11 -1
- package/types/views/ErrorBoundary.d.ts.map +1 -1
- package/types/views/ErrorBoundary.web.d.ts +13 -0
- package/types/views/ErrorBoundary.web.d.ts.map +1 -0
- package/types/views/Navigator.d.ts.map +1 -1
- package/types/views/Protected.d.ts +39 -0
- package/types/views/Protected.d.ts.map +1 -0
- package/types/views/RootErrorBoundary.d.ts +14 -8
- package/types/views/RootErrorBoundary.d.ts.map +1 -1
- package/types/views/ScrollBehavior.d.ts +8 -0
- package/types/views/ScrollBehavior.d.ts.map +1 -1
- package/types/views/SourceInspector.d.ts +35 -0
- package/types/views/SourceInspector.d.ts.map +1 -0
- package/types/views/Try.d.ts +29 -6
- package/types/views/Try.d.ts.map +1 -1
- package/types/vite/DevHead.d.ts.map +1 -1
- package/types/vite/one.d.ts.map +1 -1
- package/types/vite/plugins/SSRCSSPlugin.d.ts.map +1 -1
- package/types/vite/plugins/clientTreeShakePlugin.d.ts.map +1 -1
- package/types/vite/plugins/clientTreeShakePlugin.test.d.ts +2 -0
- package/types/vite/plugins/clientTreeShakePlugin.test.d.ts.map +1 -0
- package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
- package/types/vite/plugins/generateFileSystemRouteTypesPlugin.d.ts.map +1 -1
- package/types/vite/plugins/sourceInspectorPlugin.d.ts +3 -0
- package/types/vite/plugins/sourceInspectorPlugin.d.ts.map +1 -0
- package/types/vite/plugins/virtualEntryPlugin.d.ts.map +1 -1
- package/types/vite/types.d.ts +24 -0
- package/types/vite/types.d.ts.map +1 -1
- package/types/env.d.ts +0 -66
- /package/types/vercel/build/generate/{createSSRServerlessFunction.d.ts → createSsrServerlessFunction.d.ts} +0 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { Platform } from 'react-native'
|
|
3
|
+
|
|
4
|
+
export type BlockerState = 'unblocked' | 'blocked' | 'proceeding'
|
|
5
|
+
|
|
6
|
+
export type BlockerFunction = (args: {
|
|
7
|
+
currentLocation: string
|
|
8
|
+
nextLocation: string
|
|
9
|
+
historyAction: 'push' | 'pop' | 'replace'
|
|
10
|
+
}) => boolean
|
|
11
|
+
|
|
12
|
+
export type Blocker =
|
|
13
|
+
| {
|
|
14
|
+
state: 'unblocked'
|
|
15
|
+
reset?: undefined
|
|
16
|
+
proceed?: undefined
|
|
17
|
+
location?: undefined
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
state: 'blocked'
|
|
21
|
+
reset: () => void
|
|
22
|
+
proceed: () => void
|
|
23
|
+
location: string
|
|
24
|
+
}
|
|
25
|
+
| {
|
|
26
|
+
state: 'proceeding'
|
|
27
|
+
reset?: undefined
|
|
28
|
+
proceed?: undefined
|
|
29
|
+
location: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Stored pending navigation that was blocked.
|
|
34
|
+
* We need to restore it when the user confirms.
|
|
35
|
+
*/
|
|
36
|
+
type PendingNavigation = {
|
|
37
|
+
previousLocation: string
|
|
38
|
+
nextLocation: string
|
|
39
|
+
historyAction: 'push' | 'pop' | 'replace'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Global state for blocking
|
|
43
|
+
let currentLocation =
|
|
44
|
+
typeof window !== 'undefined' ? window.location.pathname + window.location.search : ''
|
|
45
|
+
let isBlocking = false
|
|
46
|
+
let isProceeding = false
|
|
47
|
+
let pendingNavigation: PendingNavigation | null = null
|
|
48
|
+
|
|
49
|
+
// Active blocker callbacks
|
|
50
|
+
const blockerCallbacks = new Map<
|
|
51
|
+
symbol,
|
|
52
|
+
{
|
|
53
|
+
shouldBlock: () => boolean
|
|
54
|
+
onBlock: (pending: PendingNavigation) => void
|
|
55
|
+
onProceed: () => void
|
|
56
|
+
onReset: () => void
|
|
57
|
+
}
|
|
58
|
+
>()
|
|
59
|
+
|
|
60
|
+
// Track if global listeners are set up
|
|
61
|
+
let listenersSetup = false
|
|
62
|
+
|
|
63
|
+
function setupListeners() {
|
|
64
|
+
if (listenersSetup || typeof window === 'undefined') return
|
|
65
|
+
listenersSetup = true
|
|
66
|
+
|
|
67
|
+
// Track current location on page load
|
|
68
|
+
currentLocation = window.location.pathname + window.location.search
|
|
69
|
+
|
|
70
|
+
// Listen for popstate (browser back/forward)
|
|
71
|
+
window.addEventListener('popstate', () => {
|
|
72
|
+
if (isProceeding) return
|
|
73
|
+
|
|
74
|
+
const nextLocation = window.location.pathname + window.location.search
|
|
75
|
+
|
|
76
|
+
// Check if any blocker wants to block
|
|
77
|
+
for (const [, callbacks] of blockerCallbacks) {
|
|
78
|
+
if (callbacks.shouldBlock()) {
|
|
79
|
+
// Block the navigation
|
|
80
|
+
isBlocking = true
|
|
81
|
+
pendingNavigation = {
|
|
82
|
+
previousLocation: currentLocation,
|
|
83
|
+
nextLocation,
|
|
84
|
+
historyAction: 'pop',
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Restore the previous URL immediately using history.forward() or history.back()
|
|
88
|
+
// We pushed a state when we got here, so we need to go back
|
|
89
|
+
window.history.go(1) // Go forward to restore
|
|
90
|
+
|
|
91
|
+
// Notify the blocker
|
|
92
|
+
callbacks.onBlock(pendingNavigation)
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// No blocking, update current location
|
|
98
|
+
currentLocation = nextLocation
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
// Intercept pushState and replaceState
|
|
102
|
+
const originalPushState = window.history.pushState.bind(window.history)
|
|
103
|
+
const originalReplaceState = window.history.replaceState.bind(window.history)
|
|
104
|
+
|
|
105
|
+
window.history.pushState = function (state, title, url) {
|
|
106
|
+
if (isProceeding || !url) {
|
|
107
|
+
return originalPushState(state, title, url)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const nextLocation = typeof url === 'string' ? url : url.toString()
|
|
111
|
+
|
|
112
|
+
for (const [, callbacks] of blockerCallbacks) {
|
|
113
|
+
if (callbacks.shouldBlock()) {
|
|
114
|
+
isBlocking = true
|
|
115
|
+
pendingNavigation = {
|
|
116
|
+
previousLocation: currentLocation,
|
|
117
|
+
nextLocation,
|
|
118
|
+
historyAction: 'push',
|
|
119
|
+
}
|
|
120
|
+
callbacks.onBlock(pendingNavigation)
|
|
121
|
+
return // Don't call original
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
currentLocation = nextLocation
|
|
126
|
+
return originalPushState(state, title, url)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
window.history.replaceState = function (state, title, url) {
|
|
130
|
+
if (isProceeding || !url) {
|
|
131
|
+
return originalReplaceState(state, title, url)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const nextLocation = typeof url === 'string' ? url : url.toString()
|
|
135
|
+
|
|
136
|
+
for (const [, callbacks] of blockerCallbacks) {
|
|
137
|
+
if (callbacks.shouldBlock()) {
|
|
138
|
+
isBlocking = true
|
|
139
|
+
pendingNavigation = {
|
|
140
|
+
previousLocation: currentLocation,
|
|
141
|
+
nextLocation,
|
|
142
|
+
historyAction: 'replace',
|
|
143
|
+
}
|
|
144
|
+
callbacks.onBlock(pendingNavigation)
|
|
145
|
+
return // Don't call original
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
currentLocation = nextLocation
|
|
150
|
+
return originalReplaceState(state, title, url)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Handle beforeunload (page close/refresh)
|
|
154
|
+
window.addEventListener('beforeunload', (event) => {
|
|
155
|
+
for (const [, callbacks] of blockerCallbacks) {
|
|
156
|
+
if (callbacks.shouldBlock()) {
|
|
157
|
+
event.preventDefault()
|
|
158
|
+
event.returnValue = ''
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Block navigation when a condition is met.
|
|
167
|
+
*
|
|
168
|
+
* This is useful for preventing users from accidentally leaving a page with unsaved changes.
|
|
169
|
+
* Works with both browser navigation (back/forward, URL changes) and programmatic navigation.
|
|
170
|
+
*
|
|
171
|
+
* @param shouldBlock - Either a boolean or a function that returns whether to block.
|
|
172
|
+
* When using a function, you receive the current and next locations and can make dynamic decisions.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```tsx
|
|
176
|
+
* function EditForm() {
|
|
177
|
+
* const [isDirty, setIsDirty] = useState(false)
|
|
178
|
+
* const blocker = useBlocker(isDirty)
|
|
179
|
+
*
|
|
180
|
+
* return (
|
|
181
|
+
* <>
|
|
182
|
+
* <form onChange={() => setIsDirty(true)}>
|
|
183
|
+
* {// form fields}
|
|
184
|
+
* </form>
|
|
185
|
+
*
|
|
186
|
+
* {blocker.state === 'blocked' && (
|
|
187
|
+
* <Dialog>
|
|
188
|
+
* <p>You have unsaved changes. Leave anyway?</p>
|
|
189
|
+
* <button onClick={blocker.reset}>Stay</button>
|
|
190
|
+
* <button onClick={blocker.proceed}>Leave</button>
|
|
191
|
+
* </Dialog>
|
|
192
|
+
* )}
|
|
193
|
+
* </>
|
|
194
|
+
* )
|
|
195
|
+
* }
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```tsx
|
|
200
|
+
* // Function-based blocking with location info
|
|
201
|
+
* const blocker = useBlocker(({ currentLocation, nextLocation }) => {
|
|
202
|
+
* // Only block when leaving this specific section
|
|
203
|
+
* return currentLocation.startsWith('/edit') && !nextLocation.startsWith('/edit')
|
|
204
|
+
* })
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
export function useBlocker(shouldBlock: BlockerFunction | boolean): Blocker {
|
|
208
|
+
const [state, setState] = React.useState<BlockerState>('unblocked')
|
|
209
|
+
const [blockedLocation, setBlockedLocation] = React.useState<string | null>(null)
|
|
210
|
+
const idRef = React.useRef<symbol | null>(null)
|
|
211
|
+
|
|
212
|
+
const shouldBlockRef = React.useRef(shouldBlock)
|
|
213
|
+
shouldBlockRef.current = shouldBlock
|
|
214
|
+
|
|
215
|
+
React.useEffect(() => {
|
|
216
|
+
// Only run on web
|
|
217
|
+
if (Platform.OS !== 'web' || typeof window === 'undefined') return
|
|
218
|
+
|
|
219
|
+
setupListeners()
|
|
220
|
+
|
|
221
|
+
const id = Symbol('blocker')
|
|
222
|
+
idRef.current = id
|
|
223
|
+
|
|
224
|
+
blockerCallbacks.set(id, {
|
|
225
|
+
shouldBlock: () => {
|
|
226
|
+
const block = shouldBlockRef.current
|
|
227
|
+
if (typeof block === 'function') {
|
|
228
|
+
return block({
|
|
229
|
+
currentLocation,
|
|
230
|
+
nextLocation: pendingNavigation?.nextLocation || '',
|
|
231
|
+
historyAction: pendingNavigation?.historyAction || 'push',
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
return block
|
|
235
|
+
},
|
|
236
|
+
onBlock: (pending) => {
|
|
237
|
+
setBlockedLocation(pending.nextLocation)
|
|
238
|
+
setState('blocked')
|
|
239
|
+
},
|
|
240
|
+
onProceed: () => {
|
|
241
|
+
setState('proceeding')
|
|
242
|
+
},
|
|
243
|
+
onReset: () => {
|
|
244
|
+
setState('unblocked')
|
|
245
|
+
setBlockedLocation(null)
|
|
246
|
+
},
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
return () => {
|
|
250
|
+
blockerCallbacks.delete(id)
|
|
251
|
+
}
|
|
252
|
+
}, [])
|
|
253
|
+
|
|
254
|
+
const reset = React.useCallback(() => {
|
|
255
|
+
isBlocking = false
|
|
256
|
+
pendingNavigation = null
|
|
257
|
+
setBlockedLocation(null)
|
|
258
|
+
setState('unblocked')
|
|
259
|
+
}, [])
|
|
260
|
+
|
|
261
|
+
const proceed = React.useCallback(() => {
|
|
262
|
+
if (!pendingNavigation) return
|
|
263
|
+
|
|
264
|
+
setState('proceeding')
|
|
265
|
+
isProceeding = true
|
|
266
|
+
|
|
267
|
+
const pending = pendingNavigation
|
|
268
|
+
pendingNavigation = null
|
|
269
|
+
isBlocking = false
|
|
270
|
+
|
|
271
|
+
// Execute the blocked navigation
|
|
272
|
+
requestAnimationFrame(() => {
|
|
273
|
+
if (pending.historyAction === 'pop') {
|
|
274
|
+
// Go back to where the user wanted to go
|
|
275
|
+
window.history.back()
|
|
276
|
+
} else if (pending.historyAction === 'push') {
|
|
277
|
+
window.history.pushState(null, '', pending.nextLocation)
|
|
278
|
+
} else {
|
|
279
|
+
window.history.replaceState(null, '', pending.nextLocation)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
currentLocation = pending.nextLocation
|
|
283
|
+
|
|
284
|
+
// Reset state after navigation
|
|
285
|
+
requestAnimationFrame(() => {
|
|
286
|
+
isProceeding = false
|
|
287
|
+
setBlockedLocation(null)
|
|
288
|
+
setState('unblocked')
|
|
289
|
+
})
|
|
290
|
+
})
|
|
291
|
+
}, [])
|
|
292
|
+
|
|
293
|
+
if (state === 'unblocked') {
|
|
294
|
+
return { state: 'unblocked' }
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (state === 'proceeding') {
|
|
298
|
+
return { state: 'proceeding', location: blockedLocation! }
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return {
|
|
302
|
+
state: 'blocked',
|
|
303
|
+
reset,
|
|
304
|
+
proceed,
|
|
305
|
+
location: blockedLocation!,
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Check if any active blocker wants to block navigation.
|
|
311
|
+
* Called by the router before navigating via Link.
|
|
312
|
+
* Returns true if navigation was blocked.
|
|
313
|
+
*/
|
|
314
|
+
export function checkBlocker(
|
|
315
|
+
nextLocation: string,
|
|
316
|
+
historyAction: 'push' | 'pop' | 'replace' = 'push'
|
|
317
|
+
): boolean {
|
|
318
|
+
if (Platform.OS !== 'web' || typeof window === 'undefined') {
|
|
319
|
+
return false
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (isProceeding) {
|
|
323
|
+
return false
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
for (const [, callbacks] of blockerCallbacks) {
|
|
327
|
+
if (callbacks.shouldBlock()) {
|
|
328
|
+
isBlocking = true
|
|
329
|
+
pendingNavigation = {
|
|
330
|
+
previousLocation: currentLocation,
|
|
331
|
+
nextLocation,
|
|
332
|
+
historyAction,
|
|
333
|
+
}
|
|
334
|
+
callbacks.onBlock(pendingNavigation)
|
|
335
|
+
return true
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return false
|
|
340
|
+
}
|
package/src/useFocusEffect.ts
CHANGED
|
@@ -7,12 +7,25 @@ import { useOptionalNavigation } from './link/useLoadedNavigation'
|
|
|
7
7
|
type EffectCallback = () => undefined | void | (() => void)
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Run side effects when a screen is focused. The effect runs when the screen
|
|
11
|
+
* gains focus and cleans up when it loses focus.
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
13
|
+
* @param effect - Memoized callback containing the effect, optionally returns cleanup function
|
|
14
|
+
* @param deps - Dependency array, effect re-runs when dependencies change (if focused)
|
|
15
|
+
* @link https://onestack.dev/docs/api/hooks/useFocusEffect
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* useFocusEffect(
|
|
20
|
+
* useCallback(() => {
|
|
21
|
+
* const subscription = subscribeToUpdates()
|
|
22
|
+
* return () => subscription.unsubscribe()
|
|
23
|
+
* }, []),
|
|
24
|
+
* []
|
|
25
|
+
* )
|
|
26
|
+
* ```
|
|
14
27
|
*/
|
|
15
|
-
export function useFocusEffect(effect: EffectCallback,
|
|
28
|
+
export function useFocusEffect(effect: EffectCallback, deps: any[]) {
|
|
16
29
|
const navigation = useOptionalNavigation()
|
|
17
30
|
|
|
18
31
|
useEffect(() => {
|
|
@@ -87,5 +100,5 @@ export function useFocusEffect(effect: EffectCallback, args: any[]) {
|
|
|
87
100
|
unsubscribeFocus()
|
|
88
101
|
unsubscribeBlur()
|
|
89
102
|
}
|
|
90
|
-
}, [navigation, ...
|
|
103
|
+
}, [navigation, ...deps])
|
|
91
104
|
}
|
package/src/useLoader.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { useCallback,
|
|
1
|
+
import { useCallback, useSyncExternalStore } from 'react'
|
|
2
|
+
import { registerDevtoolsFunction } from './devtools/registry'
|
|
2
3
|
import { useParams, usePathname } from './hooks'
|
|
3
4
|
import { preloadedLoaderData, preloadingLoader } from './router/router'
|
|
4
5
|
import { getLoaderPath } from './utils/cleanUrl'
|
|
@@ -15,6 +16,60 @@ type LoaderStateEntry = {
|
|
|
15
16
|
hasLoadedOnce?: boolean
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
// Timing data for loader waterfall devtool (dev only)
|
|
20
|
+
export type LoaderTimingEntry = {
|
|
21
|
+
path: string
|
|
22
|
+
startTime: number
|
|
23
|
+
moduleLoadTime?: number
|
|
24
|
+
executionTime?: number
|
|
25
|
+
totalTime?: number
|
|
26
|
+
error?: string
|
|
27
|
+
source: 'preload' | 'initial' | 'refetch'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Store timing history for devtools - only populated in development
|
|
31
|
+
const loaderTimingHistory: LoaderTimingEntry[] = []
|
|
32
|
+
const MAX_TIMING_HISTORY = 50
|
|
33
|
+
|
|
34
|
+
function recordLoaderTiming(entry: LoaderTimingEntry) {
|
|
35
|
+
if (process.env.NODE_ENV !== 'development') return
|
|
36
|
+
|
|
37
|
+
loaderTimingHistory.unshift(entry)
|
|
38
|
+
if (loaderTimingHistory.length > MAX_TIMING_HISTORY) {
|
|
39
|
+
loaderTimingHistory.pop()
|
|
40
|
+
}
|
|
41
|
+
// Dispatch event for devtools
|
|
42
|
+
if (typeof window !== 'undefined') {
|
|
43
|
+
window.dispatchEvent(new CustomEvent('one-loader-timing', { detail: entry }))
|
|
44
|
+
|
|
45
|
+
// Also dispatch error event if there was an error
|
|
46
|
+
if (entry.error) {
|
|
47
|
+
window.dispatchEvent(
|
|
48
|
+
new CustomEvent('one-error', {
|
|
49
|
+
detail: {
|
|
50
|
+
error: {
|
|
51
|
+
message: entry.error,
|
|
52
|
+
name: 'LoaderError',
|
|
53
|
+
},
|
|
54
|
+
route: {
|
|
55
|
+
pathname: entry.path,
|
|
56
|
+
},
|
|
57
|
+
timestamp: Date.now(),
|
|
58
|
+
type: 'loader',
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getLoaderTimingHistory(): LoaderTimingEntry[] {
|
|
67
|
+
return loaderTimingHistory
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Register with devtools registry so router.ts doesn't need to dynamically import us
|
|
71
|
+
registerDevtoolsFunction('getLoaderTimingHistory', getLoaderTimingHistory)
|
|
72
|
+
|
|
18
73
|
const loaderState: Record<string, LoaderStateEntry> = {}
|
|
19
74
|
const subscribers = new Set<() => void>()
|
|
20
75
|
|
|
@@ -43,7 +98,21 @@ function getLoaderState(path: string, preloadedData?: any): LoaderStateEntry {
|
|
|
43
98
|
return loaderState[path]
|
|
44
99
|
}
|
|
45
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Imperatively refetch loader data for a given path.
|
|
103
|
+
*
|
|
104
|
+
* @param pathname - The route path to refetch (e.g., '/users/123')
|
|
105
|
+
* @returns Promise that resolves when refetch completes
|
|
106
|
+
* @link https://onestack.dev/docs/api/hooks/useLoaderState#refetchloader
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```tsx
|
|
110
|
+
* await refetchLoader('/users/123')
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
46
113
|
export async function refetchLoader(pathname: string): Promise<void> {
|
|
114
|
+
const startTime = performance.now()
|
|
115
|
+
|
|
47
116
|
updateState(pathname, {
|
|
48
117
|
state: 'loading',
|
|
49
118
|
error: null,
|
|
@@ -53,8 +122,15 @@ export async function refetchLoader(pathname: string): Promise<void> {
|
|
|
53
122
|
const cacheBust = `${Date.now()}`
|
|
54
123
|
const loaderJSUrl = getLoaderPath(pathname, true, cacheBust)
|
|
55
124
|
|
|
125
|
+
const moduleLoadStart = performance.now()
|
|
56
126
|
const module = await dynamicImport(loaderJSUrl)
|
|
127
|
+
const moduleLoadTime = performance.now() - moduleLoadStart
|
|
128
|
+
|
|
129
|
+
const executionStart = performance.now()
|
|
57
130
|
const result = await module.loader()
|
|
131
|
+
const executionTime = performance.now() - executionStart
|
|
132
|
+
|
|
133
|
+
const totalTime = performance.now() - startTime
|
|
58
134
|
|
|
59
135
|
updateState(pathname, {
|
|
60
136
|
data: result,
|
|
@@ -62,19 +138,61 @@ export async function refetchLoader(pathname: string): Promise<void> {
|
|
|
62
138
|
timestamp: Date.now(),
|
|
63
139
|
hasLoadedOnce: true,
|
|
64
140
|
})
|
|
141
|
+
|
|
142
|
+
recordLoaderTiming({
|
|
143
|
+
path: pathname,
|
|
144
|
+
startTime,
|
|
145
|
+
moduleLoadTime,
|
|
146
|
+
executionTime,
|
|
147
|
+
totalTime,
|
|
148
|
+
source: 'refetch',
|
|
149
|
+
})
|
|
65
150
|
} catch (err) {
|
|
151
|
+
const totalTime = performance.now() - startTime
|
|
152
|
+
|
|
66
153
|
updateState(pathname, {
|
|
67
154
|
error: err,
|
|
68
155
|
state: 'idle',
|
|
69
156
|
})
|
|
157
|
+
|
|
158
|
+
recordLoaderTiming({
|
|
159
|
+
path: pathname,
|
|
160
|
+
startTime,
|
|
161
|
+
totalTime,
|
|
162
|
+
error: err instanceof Error ? err.message : String(err),
|
|
163
|
+
source: 'refetch',
|
|
164
|
+
})
|
|
165
|
+
|
|
70
166
|
throw err
|
|
71
167
|
}
|
|
72
168
|
}
|
|
73
169
|
|
|
74
|
-
|
|
170
|
+
// Expose refetchLoader globally for HMR in development
|
|
171
|
+
if (process.env.NODE_ENV === 'development' && typeof window !== 'undefined') {
|
|
75
172
|
;(window as any).__oneRefetchLoader = refetchLoader
|
|
76
173
|
}
|
|
77
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Access loader data with full state control including refetch capability.
|
|
177
|
+
* Use this when you need loading state or refetch; use `useLoader` for just data.
|
|
178
|
+
*
|
|
179
|
+
* @param loader - The loader function (optional - omit for just refetch/state)
|
|
180
|
+
* @returns Object with data, state ('idle' | 'loading'), and refetch function
|
|
181
|
+
* @link https://onestack.dev/docs/api/hooks/useLoaderState
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```tsx
|
|
185
|
+
* const { data, state, refetch } = useLoaderState(loader)
|
|
186
|
+
*
|
|
187
|
+
* return (
|
|
188
|
+
* <div>
|
|
189
|
+
* {state === 'loading' && <Spinner />}
|
|
190
|
+
* <button onClick={refetch}>Refresh</button>
|
|
191
|
+
* <pre>{JSON.stringify(data)}</pre>
|
|
192
|
+
* </div>
|
|
193
|
+
* )
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
78
196
|
export function useLoaderState<
|
|
79
197
|
Loader extends Function = any,
|
|
80
198
|
Returned = Loader extends (p: any) => any ? ReturnType<Loader> : unknown,
|
|
@@ -172,12 +290,15 @@ export function useLoaderState<
|
|
|
172
290
|
} else {
|
|
173
291
|
// initial load
|
|
174
292
|
const loadData = async () => {
|
|
293
|
+
const startTime = performance.now()
|
|
294
|
+
|
|
175
295
|
try {
|
|
176
296
|
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
177
297
|
const loaderJSUrl = getLoaderPath(currentPath, true)
|
|
178
298
|
const nativeLoaderJSUrl = `${loaderJSUrl}?platform=ios`
|
|
179
299
|
|
|
180
300
|
try {
|
|
301
|
+
const moduleLoadStart = performance.now()
|
|
181
302
|
const loaderJsCodeResp = await fetch(nativeLoaderJSUrl)
|
|
182
303
|
if (!loaderJsCodeResp.ok) {
|
|
183
304
|
throw new Error(`Response not ok: ${loaderJsCodeResp.status}`)
|
|
@@ -187,41 +308,91 @@ export function useLoaderState<
|
|
|
187
308
|
const result = eval(
|
|
188
309
|
`() => { var exports = {}; ${loaderJsCode}; return exports; }`
|
|
189
310
|
)()
|
|
311
|
+
const moduleLoadTime = performance.now() - moduleLoadStart
|
|
190
312
|
|
|
191
313
|
if (typeof result.loader !== 'function') {
|
|
192
314
|
throw new Error("Loader code isn't exporting a `loader` function")
|
|
193
315
|
}
|
|
194
316
|
|
|
317
|
+
const executionStart = performance.now()
|
|
195
318
|
const data = await result.loader()
|
|
319
|
+
const executionTime = performance.now() - executionStart
|
|
320
|
+
const totalTime = performance.now() - startTime
|
|
321
|
+
|
|
196
322
|
updateState(currentPath, {
|
|
197
323
|
data,
|
|
198
324
|
hasLoadedOnce: true,
|
|
199
325
|
promise: undefined,
|
|
200
326
|
})
|
|
327
|
+
|
|
328
|
+
recordLoaderTiming({
|
|
329
|
+
path: currentPath,
|
|
330
|
+
startTime,
|
|
331
|
+
moduleLoadTime,
|
|
332
|
+
executionTime,
|
|
333
|
+
totalTime,
|
|
334
|
+
source: 'initial',
|
|
335
|
+
})
|
|
201
336
|
return
|
|
202
337
|
} catch (e) {
|
|
338
|
+
const totalTime = performance.now() - startTime
|
|
203
339
|
updateState(currentPath, {
|
|
204
340
|
data: {},
|
|
205
341
|
promise: undefined,
|
|
206
342
|
})
|
|
343
|
+
recordLoaderTiming({
|
|
344
|
+
path: currentPath,
|
|
345
|
+
startTime,
|
|
346
|
+
totalTime,
|
|
347
|
+
error: e instanceof Error ? e.message : String(e),
|
|
348
|
+
source: 'initial',
|
|
349
|
+
})
|
|
207
350
|
return
|
|
208
351
|
}
|
|
209
352
|
}
|
|
210
353
|
|
|
211
354
|
// web platform
|
|
212
355
|
const loaderJSUrl = getLoaderPath(currentPath, true)
|
|
356
|
+
|
|
357
|
+
const moduleLoadStart = performance.now()
|
|
213
358
|
const module = await dynamicImport(loaderJSUrl)
|
|
359
|
+
const moduleLoadTime = performance.now() - moduleLoadStart
|
|
360
|
+
|
|
361
|
+
const executionStart = performance.now()
|
|
214
362
|
const result = await module.loader()
|
|
363
|
+
const executionTime = performance.now() - executionStart
|
|
364
|
+
|
|
365
|
+
const totalTime = performance.now() - startTime
|
|
366
|
+
|
|
215
367
|
updateState(currentPath, {
|
|
216
368
|
data: result,
|
|
217
369
|
hasLoadedOnce: true,
|
|
218
370
|
promise: undefined,
|
|
219
371
|
})
|
|
372
|
+
|
|
373
|
+
recordLoaderTiming({
|
|
374
|
+
path: currentPath,
|
|
375
|
+
startTime,
|
|
376
|
+
moduleLoadTime,
|
|
377
|
+
executionTime,
|
|
378
|
+
totalTime,
|
|
379
|
+
source: 'initial',
|
|
380
|
+
})
|
|
220
381
|
} catch (err) {
|
|
382
|
+
const totalTime = performance.now() - startTime
|
|
383
|
+
|
|
221
384
|
updateState(currentPath, {
|
|
222
385
|
error: err,
|
|
223
386
|
promise: undefined,
|
|
224
387
|
})
|
|
388
|
+
|
|
389
|
+
recordLoaderTiming({
|
|
390
|
+
path: currentPath,
|
|
391
|
+
startTime,
|
|
392
|
+
totalTime,
|
|
393
|
+
error: err instanceof Error ? err.message : String(err),
|
|
394
|
+
source: 'initial',
|
|
395
|
+
})
|
|
225
396
|
}
|
|
226
397
|
}
|
|
227
398
|
|
|
@@ -259,6 +430,26 @@ export function useLoaderState<
|
|
|
259
430
|
}
|
|
260
431
|
}
|
|
261
432
|
|
|
433
|
+
/**
|
|
434
|
+
* Load route data with SSR/SSG support. Returns the loader's data directly.
|
|
435
|
+
* For loading state and refetch capability, use `useLoaderState` instead.
|
|
436
|
+
*
|
|
437
|
+
* @param loader - The loader function exported from the route file
|
|
438
|
+
* @returns The awaited return value of your loader function
|
|
439
|
+
* @link https://onestack.dev/docs/api/hooks/useLoader
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```tsx
|
|
443
|
+
* export async function loader({ params }) {
|
|
444
|
+
* return { user: await fetchUser(params.id) }
|
|
445
|
+
* }
|
|
446
|
+
*
|
|
447
|
+
* export default function UserPage() {
|
|
448
|
+
* const { user } = useLoader(loader)
|
|
449
|
+
* return <div>{user.name}</div>
|
|
450
|
+
* }
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
262
453
|
export function useLoader<
|
|
263
454
|
Loader extends Function,
|
|
264
455
|
Returned = Loader extends (p: any) => any ? ReturnType<Loader> : unknown,
|