one
Version:
One is a new React Framework that makes Vite serve both native and web.
133 lines (127 loc) • 7.31 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: !0 });
}, __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
var Root_exports = {};
__export(Root_exports, {
Root: () => Root
});
module.exports = __toCommonJS(Root_exports);
var import_jsx_runtime = require("react/jsx-runtime"), import_native = require("@react-navigation/native"), import_universal_color_scheme = require("@vxrn/universal-color-scheme"), import_react = require("react"), import_constants = require("./constants"), import_NavigationContainer = require("./fork/NavigationContainer"), import_getURL = require("./getURL"), import_serverLocationContext = require("./router/serverLocationContext"), import_useInitializeOneRouter = require("./router/useInitializeOneRouter"), import_useViteRoutes = require("./router/useViteRoutes"), import_FlagsContext = require("./router/FlagsContext"), import_useServerHeadInsertion = require("./useServerHeadInsertion"), import_PreloadLinks = require("./views/PreloadLinks"), import_RootErrorBoundary = require("./views/RootErrorBoundary"), import_ScrollBehavior = require("./views/ScrollBehavior"), ServerAsyncLocalIDContext = /* @__PURE__ */ (0, import_react.createContext)(null);
globalThis.__vxrnGetContextFromReactContext = function() {
return (0, import_react.useContext)(ServerAsyncLocalIDContext);
};
function Root(props) {
var _globalThis___vxrnrequestAsyncLocalStore, { path, routes, routeOptions, isClient, navigationContainerProps, onRenderId } = props, context = (0, import_useViteRoutes.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 || "/", (0, import_getURL.getURL)()), store = (0, import_useInitializeOneRouter.useInitializeOneRouter)(context, location), [colorScheme] = (0, import_universal_color_scheme.useColorScheme)(), Component = store.rootComponent;
if (!Component)
throw new Error("No root component found");
var id = (0, import_react.useId)();
onRenderId == null || onRenderId(id);
var value = ((_globalThis___vxrnrequestAsyncLocalStore = globalThis.__vxrnrequestAsyncLocalStore) === null || _globalThis___vxrnrequestAsyncLocalStore === void 0 ? void 0 : _globalThis___vxrnrequestAsyncLocalStore.getStore()) || null, contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ServerAsyncLocalIDContext.Provider, {
value,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_useServerHeadInsertion.ServerRenderID.Provider, {
value: id,
children: [
/* for some reason warning if no key here */
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_NavigationContainer.NavigationContainer, {
ref: store.navigationRef,
initialState: store.initialState,
linking: store.linking,
onUnhandledAction,
theme: colorScheme === "dark" ? import_native.DarkTheme : import_native.DefaultTheme,
documentTitle: {
enabled: !1
},
...navigationContainerProps,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_serverLocationContext.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__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
children: [
/* default scroll restoration to on, but users can configure it by importing and using themselves */
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ScrollBehavior.ScrollBehavior, {}),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_RootErrorBoundary.RootErrorBoundary, {
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {})
})
]
})
)
})
}),
/* Users can override this by adding another StatusBar element anywhere higher in the component tree. */
/* {!hasViewControllerBasedStatusBarAppearance && <StatusBar style="auto" />} */
/* </GestureHandlerRootView> */
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_PreloadLinks.PreloadLinks, {}, "preload-links")
]
})
});
if (props.flags && (contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_FlagsContext.FlagsContext.Provider, {
value: props.flags,
children: contents
})), process.env.ONE_DISABLE_STRICT_MODE || (contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.StrictMode, {
children: contents
})), isClient) {
var _globalThis_SERVER_CONTEXT_KEY;
if (((_globalThis_SERVER_CONTEXT_KEY = globalThis[import_constants.SERVER_CONTEXT_KEY]) === null || _globalThis_SERVER_CONTEXT_KEY === void 0 ? void 0 : _globalThis_SERVER_CONTEXT_KEY.mode) === "spa") {
var [show, setShow] = (0, import_react.useState)(!1);
return (0, import_react.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 != null && 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() {
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Root
});
//# sourceMappingURL=Root.js.map