UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

130 lines (124 loc) 5.88 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { DarkTheme, DefaultTheme } from "@react-navigation/native"; import { useUserScheme } from "@vxrn/color-scheme"; import { createContext, StrictMode, useContext, useId, useLayoutEffect, useState } from "react"; import { SERVER_CONTEXT_KEY } from "./constants.native.js"; import { NavigationContainer as UpstreamNavigationContainer } from "./fork/NavigationContainer.native.js"; import { getURL } from "./getURL.native.js"; import { FlagsContext } from "./router/FlagsContext.native.js"; import { getLinking } from "./router/linkingConfig.native.js"; import { ServerLocationContext } from "./router/serverLocationContext.native.js"; import { useInitializeOneRouter } from "./router/useInitializeOneRouter.native.js"; import { useViteRoutes } from "./router/useViteRoutes.native.js"; import { ServerRenderID } from "./useServerHeadInsertion.native.js"; import { PreloadLinks } from "./views/PreloadLinks.native.js"; import { RootErrorBoundary } from "./views/RootErrorBoundary.native.js"; import { ScrollBehavior } from "./views/ScrollBehavior.native.js"; var ServerAsyncLocalIDContext = /* @__PURE__ */createContext(null); globalThis.__vxrnGetContextFromReactContext = function () { return useContext(ServerAsyncLocalIDContext); }; function Root(props) { var _globalThis___vxrnrequestAsyncLocalStore, { path, routes, routeOptions, isClient, navigationContainerProps, onRenderId } = props, context = useViteRoutes(routes, props.routerRoot, routeOptions, globalThis.__vxrnVersion), location = typeof window < "u" && window.location ? new URL(path || window.location.href || "/", window.location.href) : new URL(path || "/", getURL()), store = useInitializeOneRouter(context, location), userScheme = useUserScheme(), Component = store.rootComponent; if (!Component) throw new Error("No root component found"); var id = useId(); onRenderId?.(id); var value = process.env.VERCEL ? globalThis.__oneGlobalContextId : ((_globalThis___vxrnrequestAsyncLocalStore = globalThis.__vxrnrequestAsyncLocalStore) === null || _globalThis___vxrnrequestAsyncLocalStore === void 0 ? void 0 : _globalThis___vxrnrequestAsyncLocalStore.getStore()) || null, contents = /* @__PURE__ */_jsx(ServerAsyncLocalIDContext.Provider, { value, children: /* @__PURE__ */_jsxs(ServerRenderID.Provider, { value: id, children: [/* for some reason warning if no key here */ /* @__PURE__ */_jsx(UpstreamNavigationContainer, { ref: store.navigationRef, initialState: store.initialState, linking: getLinking(), onUnhandledAction, theme: userScheme.value === "dark" ? DarkTheme : DefaultTheme, documentTitle: { enabled: !1 }, ...navigationContainerProps, children: /* @__PURE__ */_jsx(ServerLocationContext.Provider, { value: location, children: (/* <GestureHandlerRootView> */ /* * Due to static rendering we need to wrap these top level views in second wrapper * View's like <GestureHandlerRootView /> generate a <div> so if the parent wrapper * is a HTML document, we need to ensure its inside the <body> */ /* @__PURE__ */_jsxs(_Fragment, { children: [/* default scroll restoration to on, but users can configure it by importing and using themselves */ /* @__PURE__ */_jsx(ScrollBehavior, {}), /* @__PURE__ */_jsx(RootErrorBoundary, { children: /* @__PURE__ */_jsx(Component, {}) })] })) }) }), /* Users can override this by adding another StatusBar element anywhere higher in the component tree. */ /* {!hasViewControllerBasedStatusBarAppearance && <StatusBar style="auto" />} */ /* </GestureHandlerRootView> */ /* @__PURE__ */_jsx(PreloadLinks, {}, "preload-links")] }) }); if (props.flags && (contents = /* @__PURE__ */_jsx(FlagsContext.Provider, { value: props.flags, children: contents })), process.env.ONE_DISABLE_STRICT_MODE || (contents = /* @__PURE__ */_jsx(StrictMode, { children: contents })), isClient) { var _globalThis_SERVER_CONTEXT_KEY; if (((_globalThis_SERVER_CONTEXT_KEY = globalThis[SERVER_CONTEXT_KEY]) === null || _globalThis_SERVER_CONTEXT_KEY === void 0 ? void 0 : _globalThis_SERVER_CONTEXT_KEY.mode) === "spa") { var [show, setShow] = useState(!1); return useLayoutEffect(function () { setShow(!0); }, []), show ? contents : null; } return contents; } return contents; } var onUnhandledAction; process.env.NODE_ENV !== "production" ? onUnhandledAction = function (action) { var payload = action.payload, message = `The action '${action.type}'${payload ? ` with payload ${JSON.stringify(action.payload)}` : ""} was not handled by any navigator.`; switch (action.type) { case "NAVIGATE": case "PUSH": case "REPLACE": case "JUMP_TO": payload?.name ? message += ` Do you have a route named '${payload.name}'?` : message += ` You need to pass the name of the screen to navigate to. This may be a bug.`; break; case "GO_BACK": case "POP": case "POP_TO_TOP": message += ` Is there any screen to go back to?`; break; case "OPEN_DRAWER": case "CLOSE_DRAWER": case "TOGGLE_DRAWER": message += ` Is your screen inside a Drawer navigator?`; break; } if (message += ` This is a development-only warning and won't be shown in production.`, process.env.NODE_ENV === "test") throw new Error(message); console.error(message); } : onUnhandledAction = function () {}; export { Root }; //# sourceMappingURL=Root.native.js.map